Posts

Post not yet marked as solved
3 Replies
1.7k Views
Hey guys, I'm working on an App that plays Apple Music tracks. Therefore I'm using MPMusicPlayerController.applicationMusicPlayer everything is working great so far - including setting the musicPlayer.currentPlaybackRate which is kind of important for my use case. Now I'm trying to setup of the lock screen-controls for my App correctly, especially because using the default ones will reset the currentPlaybackRate to 1.0 after play/pausing. Also I have to sync my internal playState if "pause" is pressed in the lock screen. Here is what I wrote: class AudioPlayerViewModel { ... private let commandCenter = MPRemoteCommandCenter.shared()     init(album: LibraryAlbum? = nil) { ...         self.setupRemoteCommandCenter()     } ... func setupRemoteCommandCenter() {         debugPrint("setupRemoteCommandCenter()")                  commandCenter.previousTrackCommand.isEnabled = false         commandCenter.previousTrackCommand.addTarget { event in             debugPrint("remote previousTrackCommand")             self.previousTrack()             return .success         }         commandCenter.nextTrackCommand.isEnabled = false         commandCenter.nextTrackCommand.addTarget { event in             debugPrint("remote nextTrackCommand")             self.nextTrack()             return .success         }         commandCenter.pauseCommand.isEnabled = false         commandCenter.pauseCommand.addTarget { event in             debugPrint("remote pauseCommand")             self.isPlaying = false             self.pausePlayback()             return .success         }         commandCenter.playCommand.isEnabled = false         commandCenter.playCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in             debugPrint("remote playCommand")             self.isPlaying = true             self.continuePlayback()             return .success         }     } } I call setupRemoteCommandCenter() once(!) before playing anything in MPMusicPlayerController.applicationMusicPlayer My problem is these handlers never get called. The lock screen-controls always remain the default ones. My code has no effect, but also throws no errors. I find several posts about this. The Apple Documentation (https://developer.apple.com/documentation/mediaplayer/handling_external_player_events_notifications) states the this should be possible. What am I doing wrong? Any help would be greatly appreciated.
Posted
by toadle.
Last updated
.