From a608bc322df411fe7988475cdb5f23846b200205 Mon Sep 17 00:00:00 2001 From: William Van Haevre Date: Wed, 14 Aug 2024 12:00:44 +0200 Subject: [PATCH] Added support on iOS for 'album' and 'artist' in the nowPlayingInfo --- CHANGELOG.md | 4 ++++ .../THEOplayerRCTNowPlayingManager.swift | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68a16c823..9dc587332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an issue on Android where the notification background would be displayed in low resolution on recent Android versions. +### Added + +- Added support on iOS for 'album' and 'artist' in the nowPlayingInfo. + ## [7.8.0] - 24-08-09 ### Added diff --git a/ios/backgroundAudio/THEOplayerRCTNowPlayingManager.swift b/ios/backgroundAudio/THEOplayerRCTNowPlayingManager.swift index fa8df3c50..294d106d0 100644 --- a/ios/backgroundAudio/THEOplayerRCTNowPlayingManager.swift +++ b/ios/backgroundAudio/THEOplayerRCTNowPlayingManager.swift @@ -54,6 +54,8 @@ class THEOplayerRCTNowPlayingManager { self.updatePlaybackState() self.nowPlayingInfo = [String : Any]() self.updateTitle(metadata.title) + self.updateArtist(metadata.metadataKeys?["artist"] as? String) + self.updateAlbum(metadata.metadataKeys?["album"] as? String) self.updateSubtitle(metadata.metadataKeys?["subtitle"] as? String) self.updateDuration(player.duration) self.updateMediaType() // video @@ -106,6 +108,18 @@ class THEOplayerRCTNowPlayingManager { } } + private func updateArtist(_ metadataArtist: String?) { + if let artist = metadataArtist { + self.nowPlayingInfo[MPMediaItemPropertyArtist] = artist + } + } + + private func updateAlbum(_ metadataAlbum: String?) { + if let album = metadataAlbum { + self.nowPlayingInfo[MPMediaItemPropertyAlbumTitle] = album + } + } + private func updateSubtitle(_ metadataSubtitle: String?) { if let subtitle = metadataSubtitle { self.nowPlayingInfo[MPMediaItemPropertyArtist] = subtitle