我是swift的新手,我在使用MPRemoteCommandCenter时遇到了问题。 当我尝试控制音频设置时,先前访问过的歌曲也会开始与当前歌曲一起播放。 我试图使用以下代码访问:
UIApplication.shared.beginReceivingRemoteControlEvents()
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.pauseCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in
//Update your button here for the pause command
self.player!.pause()
return .success
}
commandCenter.playCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in
//Update your button here for the play command
self.player!.play()
return .success
}
在结束视图时我也使用了以下内容:
UIApplication.shared.endReceivingRemoteControlEvents()