feat(recording): enhance audio session management #349
Merged
Conversation
…d app state changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes missing audio in recorded segments. Several distinct issues compounded into the same symptom (silent video on segments 2+, or after backgrounding / preview return), all stemming from how the audio-focus PR (#317) interacted with the camera's AVAudioSession.
Fixes
1. Race between activate and
recordAsynchandleRecordingStartpreviously didawait activateRecordingSession(), butRecordButtondoesn't awaitonRecordingStart— sorecordAsynccould begin before the session was reconfigured. Activation moved touseFocusEffecton the camera screen so the session is ready before the user can tap record.2. Mid-session audio thrashing
The audio session activation lived in the same
useFocusEffectas draft reload, with deps likecurrentDraftIdandmaxDurationLimitSeconds. Each state change (e.g. new draft created after recording) ran the cleanup + re-ran the effect, deactivating and reactivating AVAudioSession mid-session. This killed mic input on segments 2+. Split into a dedicated focus effect whose deps are only stableuseCallbacks.3. Mic not reattaching after preview
Returning from preview-new (which uses
expo-video) leaves AVAudioSession in a playback configuration. Our hook flips it back to record, but the already-mountedCameraViewdoesn't re-attach to the mic on category change. Extended the existing camera-remount flag from Android-only to both platforms so the capture session is rebuilt against the freshly-recording-configured session.4. Session lost after backgrounding / interruption
Incoming calls, Siri, or switching apps cause iOS to reclaim the audio session.
useFocusEffectdoesn't fire on app-foreground (only navigation focus), so the next record after resume was silent. Added anAppStatelistener inside the audio focus effect: when transitioningbackground/inactive→active, we re-activate and remount the camera.5. Reorder remount removed
app/reordersegments.tsxdoesn't use any video player, so the audio session is untouched. Removed the unnecessary remount flag.Drive-by
Cleaned up Swift warnings in
VideoConcatModule.swift: removed unusednaturalSize,preferredTransform,trackTimescalelocals and the extraneoustryon the non-throwingexporter.export().