如果来自另一个应用程序的音乐正在 spritekit 中播放,如何使 AVAudioPlayer 静音
How to mute AVAudioPlayer if music from another app is playing in spritekit
默认情况下,我注意到在 Spritekit 中,如果正在播放来自另一个应用程序的音频,它会自动关闭并播放应用程序中的音频。我该怎么做才能使相反的事情发生?如何使应用程序中的音频和音乐和音效保持静音并播放外部音乐?
您可以使用AVAudioSession
调整混音设置。您可以选择的音频类别很少,但我认为 AVAudioSessionCategoryAmbient
可能最接近您想要的:
NSError *err;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryAmbient error:&err];
if (err) {
NSLog(@"There was a problem setting the session category: %@", error);
}
默认情况下,我注意到在 Spritekit 中,如果正在播放来自另一个应用程序的音频,它会自动关闭并播放应用程序中的音频。我该怎么做才能使相反的事情发生?如何使应用程序中的音频和音乐和音效保持静音并播放外部音乐?
您可以使用AVAudioSession
调整混音设置。您可以选择的音频类别很少,但我认为 AVAudioSessionCategoryAmbient
可能最接近您想要的:
NSError *err;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryAmbient error:&err];
if (err) {
NSLog(@"There was a problem setting the session category: %@", error);
}