Skip to content

Re-activate the audio session on play(), so audio survives an interruption - #937

Merged
kingslay merged 1 commit into
kingslay:mainfrom
rochakagrawal:fix/audio-session-on-resume
Oct 2, 2026
Merged

kingslay merged 1 commit into
kingslay:mainfrom
rochakagrawal:fix/audio-session-on-resume

Conversation

@rochakagrawal

Copy link
Copy Markdown
Contributor

Playback resumed after a phone call with picture and no sound, and only came back when the viewer left the player and resumed from the detail screen.

The audio session is activated in exactly one place — KSOptions.setAudioSession(), called from the player's initialiser. iOS deactivates an app's audio session when it interrupts the app and when it suspends the process, so a call against a backgrounded player leaves the session inactive with no ended event to recover from.

Nothing activated it again, and AVPlayer renders picture perfectly well without an active audio session — which is precisely why the failure looks like a missing soundtrack rather than a broken player. Building a new player activates the session again, which is why resuming from the detail screen appeared to fix it.

Both engines resume through play(), so activating there covers every path: the automatic resume after an interruption, and the viewer pressing play afterwards — including the suspension case, which never delivers an ended event at all.

activateAudioSession() deliberately leaves the category alone. Re-setting it on a live session can glitch the audio, and the category survives deactivation unchanged. Activating an already-active session is a no-op, so calling this on every play is safe.

Nothing is removed, and no existing behaviour changes: this only adds an activation where there was none.

Playback resumed after a phone call with picture and no sound, and only came
back when the viewer left the player and resumed from the detail screen.

The audio session was activated in exactly one place: `KSOptions.setAudioSession()`,
called from the player's initialiser. iOS deactivates an app's audio session when
it interrupts the app and when it suspends the process, so a call on a
backgrounded player leaves the session inactive. Nothing activated it again, and
AVPlayer renders picture perfectly well without an active audio session - which
is precisely why the failure looked like a missing soundtrack rather than a
broken player. Resuming from the detail screen built a new player, and its
initialiser activated the session, which is why that appeared to fix it.

Both engines resume through `play()`, so activating there covers every path: the
automatic resume after an interruption, and the viewer pressing play afterwards -
including the suspension case, which never delivers an `ended` event to recover
from at all.

`activateAudioSession()` deliberately leaves the category alone. Re-setting it on
a live session can glitch the audio, and the category survives deactivation
unchanged. Activating an already-active session is a no-op, so calling it on
every play is safe.
@kingslay
kingslay merged commit 0947b3e into kingslay:main Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants