I am using MPRemoteCommandCenter and MPNowPlayingInfoCenter to control the playback of audio in the background. To setup command callbacks:
let commandCenter = MPRemoteCommandCenter.sharedCommandCenter()
commandCenter.pauseCommand.enabled = true
commandCenter.pauseCommand.addTarget(self, action: #selector(AudioPlayer.remoteCmdPause))
commandCenter.playCommand.enabled = true
commandCenter.playCommand.addTarget(self, action: #selector(AudioPlayer.remoteCmdplay))
And to update audio data:
let artWork = MPMediaItemArtwork(image: image)
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = [
MPMediaItemPropertyTitle: self.title,
MPMediaItemPropertyArtwork: artWork,
MPMediaItemPropertyPlaybackDuration: self.duration,
//MPNowPlayingInfoPropertyElapsedPlaybackTime: 0
]
This shows the pause/play button which I can handle in the remoteCmdPause and remoteCmdPlay callbacks. It also shows the volume bar which I want to either hide or register a handler so I can react to volume changes.
Is it possible to register a call back for volume changes in order to perform actions other than (or besides) increasing/decreasing the volume?
If not is it possible to hide the volume control bar from the lock screen when playing back audio in the background?