AVAudioSessionCategoryPlayback

AVAudioSessionCategoryPlayback

本文介绍了丢失“正在播放"来自MPRemoteCommandCenter的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为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的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 11:49