fix(ios): stop interrupting other apps' audio on play and fix session deactivation#894
Open
WYSIATI wants to merge 1 commit intozmxv:masterfrom
Open
fix(ios): stop interrupting other apps' audio on play and fix session deactivation#894WYSIATI wants to merge 1 commit intozmxv:masterfrom
WYSIATI wants to merge 1 commit intozmxv:masterfrom
Conversation
… deactivation Two issues in the iOS audio session management: 1. play() called [session setActive:YES] on every invocation, which interrupts other apps' audio (Spotify, Apple Music, etc.) even when the category is configured with mixWithOthers. The per-play activation triggers iOS audio route reconfiguration that pauses other audio sessions. Apps should call setActive(true) once during setup instead. play() also registered NSNotificationCenter observers for AVAudioSessionInterruptionNotification on every call without removing previous registrations. The audioSessionChangeObserver auto-resumes playback on InterruptionTypeEnded, causing unexpected sound replay after lock screen, phone calls, or Siri activations. Fix: Remove setActive:YES and observer registration from play(). Audio session lifecycle should be managed by the app, not the library. 2. setActive(false) called [session setActive:NO] without the AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation flag. Without this flag, other apps are never notified that they can resume playback, causing their audio to stay paused permanently after our session deactivates. Fix: Pass notifyOthersOnDeactivation when deactivating so other apps can resume their audio. These issues affect any app that plays short sound effects (timers, notifications, UI feedback) while the user has background music playing. Refs: zmxv#762, zmxv#480, zmxv#419, zmxv#559
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.
Problem
Two iOS audio session issues that affect apps playing short sound effects while the user has background music (Spotify, Apple Music, etc.):
1.
play()interrupts other apps' audio on every callplay()calls[[AVAudioSession sharedInstance] setActive:YES error:nil]on every invocation. Even when the app's audio category is configured withmixWithOthers, this per-play activation triggers iOS audio route reconfiguration that pauses other audio sessions.Additionally,
play()registersNSNotificationCenterobservers forAVAudioSessionInterruptionNotificationon every call without removing previous registrations. TheaudioSessionChangeObserverauto-resumes playback onInterruptionTypeEnded, causing unexpected sound replay after lock screen, phone calls, or Siri.2.
setActive(false)doesn't notify other apps to resumesetActive(false)calls[session setActive:NO error:nil]without theAVAudioSessionSetActiveOptionNotifyOthersOnDeactivationflag. Without this flag, other apps are never notified they can resume playback — their audio stays paused permanently.Fix
Remove
setActive:YESand observer registration fromplay(). Audio session lifecycle should be managed by the app viasetCategory/setActive, not implicitly by the library on every play call.AVAudioPlayer.playactivates the session implicitly when needed.Pass
notifyOthersOnDeactivationinsetActive(false). Whenactive=false, use[session setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]so other apps know they can resume.Migration
Apps that relied on the implicit
setActive:YESinplay()should add an explicit call during setup:Apps that relied on auto-resume after interruptions should implement their own
AppStatelistener.Related Issues