fix(mobile): properly pause and resume other audio during recording
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user