mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
iOS: Small refactor to centralize audio session mode management
This commit is contained in:
parent
79c3762938
commit
07b6938de1
3 changed files with 28 additions and 6 deletions
|
@ -64,6 +64,9 @@
|
||||||
[self setOriginalFrame: [gameWindow frame]];
|
[self setOriginalFrame: [gameWindow frame]];
|
||||||
[self setOriginalBounds:[gameWindow bounds]];
|
[self setOriginalBounds:[gameWindow bounds]];
|
||||||
[self setOriginalTransform:[gameWindow transform]];
|
[self setOriginalTransform:[gameWindow transform]];
|
||||||
|
|
||||||
|
// TODO: From iOS 13, should use UIScreenDidConnectNotification instead of the below.
|
||||||
|
|
||||||
// Display connected
|
// Display connected
|
||||||
[[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) {
|
[[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) {
|
||||||
UIScreen *screen = (UIScreen *) notification.object;
|
UIScreen *screen = (UIScreen *) notification.object;
|
||||||
|
@ -74,8 +77,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Ignore mute switch when connected to external display
|
// Ignore mute switch when connected to external display
|
||||||
NSError *error = nil;
|
iOSCoreAudioSetDisplayConnected(true);
|
||||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
|
|
||||||
[self updateScreen:screen];
|
[self updateScreen:screen];
|
||||||
}];
|
}];
|
||||||
// Display disconnected
|
// Display disconnected
|
||||||
|
@ -89,8 +91,7 @@
|
||||||
UIScreen *newScreen = [[self extDisplays] lastObject];
|
UIScreen *newScreen = [[self extDisplays] lastObject];
|
||||||
[self updateScreen:newScreen];
|
[self updateScreen:newScreen];
|
||||||
} else {
|
} else {
|
||||||
NSError *error = nil;
|
iOSCoreAudioSetDisplayConnected(false);
|
||||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
|
|
||||||
[self updateScreen:[UIScreen mainScreen]];
|
[self updateScreen:[UIScreen mainScreen]];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
|
@ -20,3 +20,8 @@
|
||||||
|
|
||||||
void iOSCoreAudioInit();
|
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
|
#define SAMPLE_RATE 44100
|
||||||
|
|
||||||
static AudioComponentInstance audioInstance = nil;
|
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);
|
int NativeMix(short *audio, int numSamples, int sampleRate);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue