[英]How do I turn off another app's audio when my app's audio starts?
So, I need two things: 所以,我需要两件事:
When my app starts, and another app's audio is already playing, I don't want to stop that other app's audio. 当我的应用程序启动并且另一个应用程序的音频已经在播放时,我不想停止其他应用程序的音频。
When my app's audio starts playing (the user initiates this action) I want any other app's audio that may be currently playing to stop. 当我的应用程序的音频开始播放时(用户启动此操作),我希望停止当前正在播放的其他任何应用程序的音频。
I've already accomplished #1, but need some help figuring out #2. 我已经完成了#1的工作,但需要一些帮助来找出#2。
Here's the code I have in my App Delegate applicationDidFinishLaunchingWithOptions method that makes #1 work: 这是我在应用程序委托applicationDidFinishLaunchingWithOptions方法中拥有的代码,该代码使#1起作用:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:nil];
So, the key was to set the options to 0 when I actually started playing the audio in my app with a category of AVAudioSessionCategoryPlayback. 因此,关键是当我实际上开始使用AVAudioSessionCategoryPlayback类别在应用中播放音频时,将选项设置为0。 If you just don't specify the options when you change the category, it seems to assume that you want to use the originally specified options.
如果只是在更改类别时未指定选项,则似乎假设您要使用最初指定的选项。 That's my guess anyway.
无论如何,这是我的猜测。
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:0
error:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.