I discovered that what was causing the MPNowPlayingInfoCenter to be update was the AVPlayerViewController (as I believed) setting controller.updatesNowPlayingInfoCenter = false prevented this unwanted update
Now a new issue appears, the MPNowPlayingInfoCenter doesn't appear at all
On the init() I have this line to monitor the playback status
player.publisher(for: \.timeControlStatus)
.sink { [weak self] status in
switch status {
case .playing:
self?.isPlaying = true
try? AVAudioSession.sharedInstance().setActive(true)
self?.setupNowPlaying()
case .paused:
self?.isPlaying = false
case .waitingToPlayAtSpecifiedRate:
break
@unknown default:
break
}
}
.store(in: &subscriptions)
Here's the function that updates (or at least should) update the MPNowPlayingInfo
func setupNowPlaying() {
var nowPlayingInfo = [String: Any]()
nowPlayingInfo[MPNowPlayingInfoPropertyMediaType] = MPNowPlayingInfoMediaType.audio.rawValue
nowPlayingInfo[MPNowPlayingInfoPropertyIsLiveStream] = false
nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate
nowPlayingInfo[MPMediaItemPropertyTitle] = "Track Title"
nowPlayingInfo[MPMediaItemPropertyArtist] = "Track Artist"
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = duration
nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = currentTime
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
}
I feel that I'm close to the answer but still out of reach