问题描述
我正在为iOS创建可以使用MPRemoteCommandCenter
进行控制的应用程序.效果很好.
I am creating an application for iOS that can be controlled using the MPRemoteCommandCenter
. This works fine.
将应用程序AVAudioSession
类别从AVAudioSessionCategoryPlayback
更改为AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers
时,它将停止接收远程控制事件.很好.
When changing the application AVAudioSession
category from AVAudioSessionCategoryPlayback
to AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers
, it stops receiving remote control events. This is fine.
但是当我将类别更改回AVAudioSessionCategoryPlayback
时,没有收到预期的MPRemoteCommandCenter
事件.
But when I change the category back to AVAudioSessionCategoryPlayback
, I do not receive events from MPRemoteCommandCenter
as expected.
如何为我的应用程序恢复正在播放"状态?
How can I reclaim "Now Playing" status for my application?
推荐答案
我发现设置AVAudioSessionCategory
时保留了这些选项.因此,通过先调用setCategory(AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers)
然后再调用setCategory(AVAudioSessionCategoryPlayback)
,.MixWithOthers
选项始终有效.
I did discover that when setting AVAudioSessionCategory
the options are retained. So by calling setCategory(AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers)
first and then setCategory(AVAudioSessionCategoryPlayback)
later, the .MixWithOthers
option was always in effect.
我找不到AVAudioSessionCategoryOptions.None
选项,但是提供一个空数组确实重置了类别选项.
I was unable to find a AVAudioSessionCategoryOptions.None
option, but supplying an empty array did reset the category options.
.setCategory(AVAudioSessionCategoryPlayback, withOptions: [])
这篇关于丢失“正在播放"来自MPRemoteCommandCenter的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!