Instead of using the UIEvent stream with remoteControlReceivedWithEvent I would recommend using MPRemoteCommandCenter to control the previous / next / play / pause actions on the lock screen and in the control center.
import MediaPlayer // ... let commandCenter = MPRemoteCommandCenter.sharedCommandCenter() commandCenter.previousTrackCommand.enabled = true; commandCenter.previousTrackCommand.addTarget(self, action: "previousTrack") commandCenter.nextTrackCommand.enabled = true commandCenter.nextTrackCommand.addTarget(self, action: "nextTrack") commandCenter.playCommand.enabled = true commandCenter.playCommand.addTarget(self, action: "playAudio") commandCenter.pauseCommand.enabled = true commandCenter.pauseCommand.addTarget(self, action: "pauseAudio")
Where previousTrack , nextTrack , playAudio and pauseAudio are all the functions in your class where you control the player.
You may need to explicitly disable the forward and backward scrolling of commands:
commandCenter.skipBackwardCommand.enabled = false commandCenter.skipForwardCommand.enabled = false
source share