【发布时间】:2018-01-14 10:12:14
【问题描述】:
我创建了具有两个不同音频播放器(收音机和 MP3)的应用程序。为两个播放器使用 MPRemoteCommandCenter 从锁定屏幕管理播放器。这是代码sn-p:
MP3 播放器
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.nextTrackCommand.isEnabled = true
commandCenter.nextTrackCommand.addTarget(self, action: #selector(next))
commandCenter.previousTrackCommand.isEnabled = true
commandCenter.previousTrackCommand.addTarget(self, action: #selector(previous))
commandCenter.playCommand.isEnabled = true
commandCenter.playCommand.addTarget(self, action: #selector(playPause)
commandCenter.pauseCommand.isEnabled = true
commandCenter.pauseCommand.addTarget(self, action: #selector(playPause))
收音机播放器
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.playCommand.isEnabled = true
commandCenter.playCommand.removeTarget(self, action:nil)
commandCenter.playCommand.addTarget(self, action: #selector(radioPlayFromLock))
commandCenter.pauseCommand.isEnabled = true
commandCenter.pauseCommand.removeTarget(self, action:nil)
commandCenter.pauseCommand.addTarget(self, action: #selector(radioJPStop))
commandCenter.nextTrackCommand.isEnabled = false
commandCenter.previousTrackCommand.isEnabled = false
两者都可以单独正常工作,但请按照以下步骤操作:
- 播放 MP3 播放器
- 之后播放 Radio
- 并试图从锁定屏幕停止
- 列表项
由于寻找 MP3 播放器方法而崩溃。这意味着目标方法不会针对播放/暂停命令进行更新。任何帮助将不胜感激。
【问题讨论】:
标签: ios iphone swift audio mpremotecommandcenter