mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
iOS: Small refactor to centralize audio session mode management
This commit is contained in:
parent
79c3762938
commit
07b6938de1
@ -64,6 +64,9 @@
|
||||
[self setOriginalFrame: [gameWindow frame]];
|
||||
[self setOriginalBounds:[gameWindow bounds]];
|
||||
[self setOriginalTransform:[gameWindow transform]];
|
||||
|
||||
// TODO: From iOS 13, should use UIScreenDidConnectNotification instead of the below.
|
||||
|
||||
// Display connected
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) {
|
||||
UIScreen *screen = (UIScreen *) notification.object;
|
||||
@ -74,8 +77,7 @@
|
||||
return;
|
||||
}
|
||||
// Ignore mute switch when connected to external display
|
||||
NSError *error = nil;
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
|
||||
iOSCoreAudioSetDisplayConnected(true);
|
||||
[self updateScreen:screen];
|
||||
}];
|
||||
// Display disconnected
|
||||
@ -89,8 +91,7 @@
|
||||
UIScreen *newScreen = [[self extDisplays] lastObject];
|
||||
[self updateScreen:newScreen];
|
||||
} else {
|
||||
NSError *error = nil;
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
|
||||
iOSCoreAudioSetDisplayConnected(false);
|
||||
[self updateScreen:[UIScreen mainScreen]];
|
||||
}
|
||||
}];
|
||||
|
@ -19,4 +19,9 @@
|
||||
// Originally written by jtraynham
|
||||
|
||||
void iOSCoreAudioInit();
|
||||
void iOSCoreAudioShutdown();
|
||||
void iOSCoreAudioShutdown();
|
||||
|
||||
// Ignore mute switch when connected to external display.
|
||||
// Also, obey other settings.
|
||||
void iOSCoreAudioUpdateSession();
|
||||
void iOSCoreAudioSetDisplayConnected(bool connected);
|
@ -28,6 +28,22 @@
|
||||
#define SAMPLE_RATE 44100
|
||||
|
||||
static AudioComponentInstance audioInstance = nil;
|
||||
static bool g_displayConnected = false;
|
||||
|
||||
void iOSCoreAudioUpdateSession() {
|
||||
NSError *error = nil;
|
||||
// Default mode
|
||||
if (g_displayConnected) {
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
|
||||
} else {
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
|
||||
}
|
||||
}
|
||||
|
||||
void iOSCoreAudioSetDisplayConnected(bool connected) {
|
||||
g_displayConnected = connected;
|
||||
iOSCoreAudioUpdateSession();
|
||||
}
|
||||
|
||||
int NativeMix(short *audio, int numSamples, int sampleRate);
|
||||
|
||||
@ -75,7 +91,7 @@ void iOSCoreAudioInit()
|
||||
NSLog(@"%@", error.localizedFailureReason);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (audioInstance) {
|
||||
// Already running
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user