[英]Music from other apps stops playing when my app starts
当我启动应用程序时,来自其他应用程序的音乐将停止播放。
我试过在didFinishLaunchingWithOptions
添加setCategory:AVAudioSessionCategoryAmbient
,但音乐在setCategory:AVAudioSessionCategoryAmbient
启动时仍会停止。 如果我开始播放音乐并使用主屏幕按钮返回到应用程序,则音乐将继续播放。 有没有针对第一次启动问题的解决方法?
我添加的代码段:
// make sure music plays while sounds play.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
尝试以下方法:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions:0 error:nil];
或如果上面的方法不起作用:
[[AVAudioSession sharedInstance] setActive:NO error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
编辑:
如果以上方法都不适合您,那么您可以尝试将您认为合适的其他类别与AVAudioSessionCategoryOptionMixWithOthers一起设置(如果适用于您的用例)。
确定此会话中的音频是否与其他音频应用程序中活动会话中的音频混合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.