好的,这里的 Apple 指挥中心有一些问题,播放背景音频/在锁定屏幕上,不明白为什么。看起来很简单,但我什至没有在指挥中心可靠地显示剧集信息,绝对不能播放/暂停。
首先我开始音频会话:
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: .mixWithOthers)
print("Playback OK")
try AVAudioSession.sharedInstance().setActive(true)
print("Session is Active")
} catch {
print(error)
}
然后我将我的命令中心按钮设置为明确启用:
UIApplication.shared.beginReceivingRemoteControlEvents()
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.skipForwardCommand.isEnabled = true
commandCenter.skipBackwardCommand.isEnabled = true
commandCenter.nextTrackCommand.isEnabled = true
commandCenter.togglePlayPauseCommand.isEnabled = true
// commandCenter.previousTrackCommand.isEnabled = true
// commandCenter.togglePlayPauseCommand.isEnabled = true
commandCenter.togglePlayPauseCommand.addTarget(self, action:#selector(togglePlayPause))
// commandCenter.nextTrackCommand.addTarget(self, action:#selector(nextTrackForward))
// commandCenter.previousTrackCommand.addTarget(self, action:#selector(nextTrackBack))
commandCenter.skipForwardCommand.addTarget(self, action:#selector(ffPressed))
commandCenter.skipBackwardCommand.addTarget(self, action:#selector(rwPressed))
如果这对音频很重要,这里是 lldb plist 键:
这里有什么问题?