Hi From the following statement in the official apple doc
Users can initiate audio playback commands through an external headset or accessory. These commands are sent to the app as remote-control events. To receive remote-control events in your app, you must use an application music player. If you use the system music player, your app uses the Music app to play audio, which means that the Music app is the “now playing” app. The Music app receives the remote control events, not your app. However, the Music app responds to remote control events on your behalf. For example, if your app plays audio using the system music player, and you switch from your app to the iOS device’s Now Playing controls, the controls work as expected. That is, you can play or pause audio or skip to the next and previous items.
I thought one should receive remotecontrols in his app when using the following function to get a musicplayer controller
class func applicationMusicPlayer() -> MPMusicPlayerController
however when my app plays music using it with background music enabled in the app settings in XCode, pressing the next track or previous track button in the lock screen don't call the registered target selector in MPRemoteCommandCenter.
MPRemoteCommandCenter.sharedCommandCenter().previousTrackCommand.addTargetWithHandler( { (MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus in
print("Previous")
return MPRemoteCommandHandlerStatus.Success
})
previous never gets printed.
this is how a setup the music player
player = MPMusicPlayerController.applicationMusicPlayer()
player.setQueueWithItemCollection(mediaItem)
player.nowPlayingItem = mediaItem.representativeItem!
player.play()