Fixed audio not coming out of the phone speakers while recording on iOS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m
index c20d9b0..91d8b97 100644
--- a/src/audio/coreaudio/SDL_coreaudio.m
+++ b/src/audio/coreaudio/SDL_coreaudio.m
@@ -326,12 +326,18 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
@autoreleasepool {
AVAudioSession *session = [AVAudioSession sharedInstance];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
/* Set category to ambient by default so that other music continues playing. */
NSString *category = AVAudioSessionCategoryAmbient;
+ NSString *mode = AVAudioSessionModeDefault;
+ NSUInteger options = 0;
NSError *err = nil;
if (open_playback_devices && open_capture_devices) {
category = AVAudioSessionCategoryPlayAndRecord;
+#if !TARGET_OS_TV
+ options = AVAudioSessionCategoryOptionDefaultToSpeaker;
+#endif
} else if (open_capture_devices) {
category = AVAudioSessionCategoryRecord;
} else {
@@ -348,10 +354,18 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
}
}
- if (![session setCategory:category error:&err]) {
- NSString *desc = err.description;
- SDL_SetError("Could not set Audio Session category: %s", desc.UTF8String);
- return NO;
+ if ([session respondsToSelector:@selector(setCategory:mode:options:error:)]) {
+ if (![session setCategory:category mode:mode options:options error:&err]) {
+ NSString *desc = err.description;
+ SDL_SetError("Could not set Audio Session category: %s", desc.UTF8String);
+ return NO;
+ }
+ } else {
+ if (![session setCategory:category error:&err]) {
+ NSString *desc = err.description;
+ SDL_SetError("Could not set Audio Session category: %s", desc.UTF8String);
+ return NO;
+ }
}
if (open && (open_playback_devices + open_capture_devices) == 1) {