From f560f4793d4910df757aa0761ff4a454f2f5119e Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 2 Nov 2019 10:35:28 +1000 Subject: [PATCH] iOS: Try adding support for Bluetooth routing. --- miniaudio.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 98d9342f..49489e8b 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -1993,6 +1993,10 @@ typedef struct ma_bool32 tryAutoSpawn; /* Enables autospawning of the PulseAudio daemon if necessary. */ } pulse; struct + { + ma_bool32 noBluetoothRouting; + } coreaudio; + struct { const char* pClientName; ma_bool32 tryStartServer; @@ -20401,9 +20405,21 @@ ma_result ma_context_init__coreaudio(const ma_context_config* pConfig, ma_contex #if defined(MA_APPLE_MOBILE) @autoreleasepool { AVAudioSession* pAudioSession = [AVAudioSession sharedInstance]; + AVAudioSessionCategoryOptions options = 0; + ma_assert(pAudioSession != NULL); - [pAudioSession setCategory: AVAudioSessionCategoryPlayAndRecord error:nil]; + /* + Try enabling routing to Bluetooth devices. The AVAudioSessionCategoryOptionAllowBluetoothA2DP is only available + starting from iOS 10 so I'm doing a version check before enabling this. + */ + if (!pConfig->coreaudio.noBluetoothRouting) { + if ([[[UIDevice currentDevice] systemVersion] compare:@"10.0" options:NSNumericSearch] != NSOrderedAscending) { + options = 0x20; /* 0x20 = AVAudioSessionCategoryOptionAllowBluetoothA2DP */ + } + } + + [pAudioSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions:options error:nil]; /* By default we want miniaudio to use the speakers instead of the receiver. In the future this may be customizable. */ ma_bool32 useSpeakers = MA_TRUE;