简体   繁体   中英

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. 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. There are few possible audio categories you can choose, but I think AVAudioSessionCategoryAmbient is probably closest to what you want:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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