I’ve developed an iOS audio playback software utilizing SwiftUI, AVFoundation, MediaPlayer, and ActivityKit. The PlayAudioService class handles audio playback, together with background play, lock display controls, and updating the now enjoying info for the lock display and management middle.
The app is able to enjoying audio within the background efficiently. Nevertheless, regardless of accurately establishing the MPNowPlayingInfoCenter with the mandatory keys (title, artist, art work, length, and elapsed time), the lock display and management middle should not displaying the proper playback info or controls. By logging, I can verify that my updateNowPlayingInfo() methodology is being referred to as and the MPNowPlayingInfoCenter.default().nowPlayingInfo dictionary incorporates the anticipated values. Regardless of this, these updates don’t mirror on the person interface.
This is a related snippet from my PlayAudioService class the place I replace the now enjoying data:
func updateNowPlayingInfo() {
print("Updating playback data")
DispatchQueue.predominant.async {
if let participant = self.participant {
var nowPlayingInfo = [String: Any]()
nowPlayingInfo[MPMediaItemPropertyTitle] = self.trackTitle
nowPlayingInfo[MPMediaItemPropertyArtist] = "Artist Identify"
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = participant.length
nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = participant.currentTime
if let albumArt = self.albumArt {
let art work = MPMediaItemArtwork(boundsSize: albumArt.dimension) { _ in
return albumArt
}
nowPlayingInfo[MPMediaItemPropertyArtwork] = art work
}
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
print(MPNowPlayingInfoCenter.default().nowPlayingInfo ?? "No Now Enjoying Information")
}
}
}
After I log the MPNowPlayingInfoCenter.default().nowPlayingInfo, it prints out the next info, indicating that the information is ready accurately:
[
"MPNowPlayingInfoPropertyElapsedPlaybackTime": 51.41918367346939,
"artist": "Artist Name",
"artwork": ,
"playbackDuration": 728.6668027210884,
"title": "84ABB1F1-AA30-45A1-BEE9-B22363EE79D2.mp3"
]
What might be inflicting the lock display and management middle to not show the proper playback info regardless that MPNowPlayingInfoCenter appears to be up to date correctly? Are there any widespread pitfalls or extra settings I might need missed?