fix(mobile): properly pause and resume other audio during recording

This commit is contained in:
Arjun Patel
2026-05-26 10:21:42 -07:00
parent e7fed5f037
commit 0eddf4639a
3 changed files with 51 additions and 9 deletions
@@ -0,0 +1,24 @@
import { setAudioModeAsync, setIsAudioActiveAsync } from "expo-audio";
// Around camera/mic recording we switch the iOS audio session to playAndRecord
// with `doNotMix`, which cleanly interrupts other apps' audio (Spotify, Apple
// Music, podcasts). On release we restore a mixable mode and then *deactivate*
// the session — the deactivation is what passes notifyOthersOnDeactivation to
// AVAudioSession, which is the signal that lets the previously-playing app
// auto-resume. Just changing the category is not enough.
export async function acquireRecordingAudioSession() {
await setAudioModeAsync({
allowsRecording: true,
playsInSilentMode: true,
interruptionMode: "doNotMix",
});
}
export async function releaseRecordingAudioSession() {
await setAudioModeAsync({
allowsRecording: false,
playsInSilentMode: true,
interruptionMode: "mixWithOthers",
});
await setIsAudioActiveAsync(false);
}