简体   繁体   English

如果另一个应用程序中的音乐正在spritekit中播放,如何使AVAudioPlayer静音

[英]How to mute AVAudioPlayer if music from another app is playing in spritekit

By default, I notice that in Spritekit, if audio from another app is playing, it is automatically turned off and the audio in the app plays. 默认情况下,我注意到在Spritekit中,如果正在播放其他应用程序的音频,则会自动将其关闭,并播放该应用程序中的音频。 How do I make it so that the opposite occurs? 我如何做到相反 How do I make it so that the audio and music and sound effects in the app remain mute and external music plays? 如何使应用程序中的音频,音乐和声音效果保持静音并播放外部音乐?

You can use AVAudioSession to adjust the mixing settings. 您可以使用AVAudioSession来调整混音设置。 There are few possible audio categories you can choose, but I think AVAudioSessionCategoryAmbient is probably closest to what you want: 您可以选择的音频类别很少,但我认为AVAudioSessionCategoryAmbient可能与您想要的最接近:

NSError *err;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryAmbient error:&err];

if (err) {
    NSLog(@"There was a problem setting the session category: %@", error);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM