我正在从本地通知中发起一些背景音乐。我收到以下错误代码:错误域= NSOSStatusErrorDomain代码= 560557684“(null)”,这是
AVAudioSessionErrorCodeCannotInterruptOthers尝试进行 当应用程序在。时,使不可混合的音频会话处于活动状态 背景。 仅当应用是NowPlaying应用时才允许这样做。
我找不到很多关于成为NowPlaying App意味着什么的文档。目前我正在调用两个
UIApplication.shared.beginReceivingRemoteControlEvents()
首先是和NowPlayingInfo函数。
MPNowPlayingInfoCenter.default().nowPlayingInfo = [
MPMediaItemPropertyTitle: currentPodName + " - " + currentEpName,
MPMediaItemPropertyArtist: currentAuthor,
MPMediaItemPropertyPlaybackDuration: CMTimeGetSeconds(self.player.currentItem!.duration),
MPNowPlayingInfoPropertyElapsedPlaybackTime: CMTimeGetSeconds(self.player.currentTime()),
MPMediaItemPropertyArtwork: MPMediaItemArtwork.init(boundsSize: image.size, requestHandler: { (size) -> UIImage in
return image
})
]
在设置AV会话之前
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
print("Playback OK")
try AVAudioSession.sharedInstance().setActive(true)
print("Session is Active")
} catch {
print(error)
}
我是从
开始的func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
因此每次收到本地通知时都会调用它。我继续得到错误。还有什么我可以做的,以允许我的应用程序从后台启动不可混合的音频会话?
如果我无法从后台启动不可混合的音频会话,我可以使音频混合,但我无法访问MPRemoteCommandCenter,它无法与可混合的音乐集成。有没有办法从后台启动并保留MPRemoteCommandCenter?