feat: stop background audio during recording, resume after#317
Open
adithya1012 wants to merge 2 commits intomieweb:mainfrom
Open
feat: stop background audio during recording, resume after#317adithya1012 wants to merge 2 commits intomieweb:mainfrom
adithya1012 wants to merge 2 commits intomieweb:mainfrom
Conversation
…sions on Android and iOS
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.
Description
Pulse now will handle the background app playing while recording the audio.
Added a local native Expo module (audio-focus) that directly controls the OS-level audio focus on both Android and iOS. A
useAudioSessionhook integrates it into the recording flow.Demo
LINK
How it works
Android
requestAudioFocus→AudioManager.requestAudioFocus(AUDIOFOCUS_GAIN_TRANSIENT)— OS signal that causes Spotify/podcasts to pauseabandonAudioFocus→AudioManager.abandonAudioFocus()— tells Spotify/podcasts they can resumeAUDIOFOCUS_GAIN_TRANSIENT(notAUDIOFOCUS_GAIN) is intentional — transient means Spotify receivesAUDIOFOCUS_LOSS_TRANSIENTand automatically resumes when we're done.iOS
requestAudioFocus→AVAudioSession.setActive(true)— activates session, interrupting other appsabandonAudioFocus→AVAudioSession.setActive(false, options: .notifyOthersOnDeactivation)— the.notifyOthersOnDeactivationflag is the iOS signal that tells Spotify/Apple Music to resume. Without this flag, they stay paused indefinitely.setAudioModeAsync(expo-audio) configures the AVAudioSession category (playAndRecord,doNotMix) on both platforms before focus is claimed.Files changed
activateRecordingSession/deactivateRecordingSessionMODIFY_AUDIO_SETTINGSpermissionaudio-focusAndroid build outputBug fixed during implementation
expo/expo#34025 — passing both
interruptionMode(iOS) andinterruptionModeAndroidin the samesetAudioModeAsynccall crashes on Android with a Kotlin enum cast error. Fixed by spreading only the platform-relevant key viaPlatform.OS.Testing
NOTE: Tested in Android. This need to be tested in iOS.