如何從AVAudioSessionCategory中刪除AVAudioSessionCategoryOptions? - How to remove AVAudioSessionCategoryOptions from AVAudioSessionCate

如何從AVAudioSessionCategory中刪除AVAudioSessionCategoryOptions? - How to remove AVAudioSessionCategoryOptions from AVAudioSessionCate,第1张

I set my AVAudioSessionCategory like this with options:

我使用選項設置我的AVAudioSessionCategory:

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: AVAudioSessionCategoryOptions.mixWithOthers)
try AVAudioSession.sharedInstance().setActive(true) 

Later in my Code I want to remove AVAudioSessionCategoryOptions.mixWithOthers from the AVAudioSessionCategory.

稍后在我的代碼中,我想從AVAudioSessionCategory中刪除AVAudioSessionCategoryOptions.mixWithOthers。

According to documentation this should do the trick:

根據文檔,這應該做的伎倆:

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)

However it does not work in iOS 9 and iOS 10. It does not throw any error, but the option is not removed. I already reported this as a bug to Apple.

但是它在iOS 9和iOS 10中不起作用。它不會拋出任何錯誤,但不會刪除該選項。我已將此報告為Apple的錯誤。

As long as this is not fixed: Is there any other way to achieve what I want?

只要不修復:有沒有其他方法可以實現我想要的?

Please keep in mind: Working with AVAudioSessionCategory can only be tested on a real device.

請記住:使用AVAudioSessionCategory只能在真實設備上進行測試。

1 个解决方案

#1


2  

It can be done like this:

它可以這樣做:

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: AVAudioSessionCategoryOptions(rawValue: 0))

It does not work while the app is in background though.

雖然應用程序處於后台,但它不起作用。

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复