简体   繁体   中英

Hide or handle volume bar on iOS lock screen when playing audio in background

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?

As for the callback part of my question, there does not seem to be any specific remote command to handle the volume changes from the lock screen. Just observing the "outputVolume" (via observeValueForKeyPath) does the trick.
Hiding the volume bar is still a question but not necessary anymore (at least for my part).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM