我是 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()