iOS: Implement the two new audio flags (respect silent mode, mix with other apps)

This commit is contained in:
Henrik Rydgård committed 2024-05-27 23:35:31 +02:00
1 parent 35c40196d4
commit 5e9878cfda
1 file changed
+29 -3
+29 -3
View File
@@ -33,14 +33,40 @@ static bool g_displayConnected = false;
void iOSCoreAudioUpdateSession() {
NSError *error = nil;
// Default mode
if (g_displayConnected) {
INFO_LOG(AUDIO, "Display connected, setting Playback mode");
// Special handling when a display is connected. Always exclusive.
// Let's revisit this later.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
} else {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
return;
}
INFO_LOG(AUDIO, "RespectSilentMode: %d MixWithOthers: %d", g_Config.bAudioRespectSilentMode, g_Config.bAudioMixWithOthers);
// Hacky hack to force iOS to re-evaluate.
// Switching from CatogoryPlayback to CategoryPlayback with an option otherwise does nothing.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAudioProcessing error:&error];
// Here, we apply the settings.
const bool mixWithOthers = g_Config.bAudioMixWithOthers;
if (g_Config.bAudioMixWithOthers) {
if (g_Config.bAudioRespectSilentMode) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
} else {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];
}
} else {
if (g_Config.bAudioRespectSilentMode) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:&error];
} else {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:0 error:&error];
}
// Can't achieve exclusive + respect silent mode
}
if (error) {
NSLog(@"%@", error);
}
}
void iOSCoreAudioSetDisplayConnected(bool connected) {