Skip to content

Commit

Permalink
iOS: configAudioSystem(): Sets AVAudioSessionCategoryOptionOverrideMu…
Browse files Browse the repository at this point in the history
…tedMicrophoneInterruption option to allow for simultaneous playback & audio input
  • Loading branch information
birdofpreyru committed Sep 13, 2023
1 parent dbdf8c6 commit 810d999
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default function App() {
const ia = await getInputAvailable();
setInputAvailable(ia ? 'YES' : 'NO');
if (ia) {
await configAudioSystem();
stream = new InputAudioStream(
AUDIO_SOURCES.RAW,
SAMPLE_RATE_BASE,
Expand Down
20 changes: 17 additions & 3 deletions ios/ReactNativeAudio.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,24 @@ - (dispatch_queue_t)methodQueue
}

NSError *error = nil;

AVAudioSessionCategoryOptions options =
AVAudioSessionCategoryOptionAllowBluetooth |
AVAudioSessionCategoryOptionAllowBluetoothA2DP |
AVAudioSessionCategoryOptionDefaultToSpeaker;

// NOTE: The AVAudioSessionCategoryOptionOverrideMutedMicrophoneInterruption
// option triggers an error if one attempts to set it for a category that does
// not support audio input. For categories that do support it, it allows for
// simultaneous playback and audio input.
if (category == AVAudioSessionCategoryPlayAndRecord) {
if (@available(iOS 14.5, *)) {
options |= AVAudioSessionCategoryOptionOverrideMutedMicrophoneInterruption;
}
}

BOOL res = [audioSession setCategory:category
withOptions:(AVAudioSessionCategoryOptionAllowBluetooth |
AVAudioSessionCategoryOptionAllowBluetoothA2DP |
AVAudioSessionCategoryOptionDefaultToSpeaker)
withOptions:options
error:&error];

// TODO: Currently here, and in the next rejection, although we include
Expand Down

0 comments on commit 810d999

Please sign in to comment.