Skip to content

ios: recover the stream after an audio session interruption - #1295

Merged
roderickvd merged 3 commits into
RustAudio:masterfrom
roderickvd:ios-audio-session-interruption-review
Jul 30, 2026
Merged

ios: recover the stream after an audio session interruption#1295
roderickvd merged 3 commits into
RustAudio:masterfrom
roderickvd:ios-audio-session-interruption-review

Conversation

@roderickvd

Copy link
Copy Markdown
Member

Continues #1289 (by @benface), addressing the second review round on top of it: pause() no longer leaves a stale flag that could restart a paused stream when the next interruption ends, unsafe is narrowed to the extern-static reads that need it, and the field comment/changelog wording are trimmed.

The playing/interrupted bool pair became a single PlaybackState enum (Stopped/Playing/Interrupted), which also removes the race the two independent bools were prone to.

Closes #1289.

benface and others added 2 commits July 26, 2026 17:46
A call, an alarm or Siri stops the audio unit through CoreAudio
without going through cpal, so `StreamInner::playing` is left
reading `true` for a unit that is no longer running. `play` then
short-circuits on that flag, and the stream can never be resumed:
the caller sees a successful `play` and silence, with no error to
explain it.

`AVAudioSessionInterruptionNotification` is now observed alongside
the route-change and media-services notifications the manager
already handles. Beginning an interruption stops the unit through
the normal path, bringing the flag back in step with reality. When
one ends carrying `ShouldResume`, the session is reactivated — it
is left inactive, and a unit cannot start against an inactive
session — and the unit started again, so a caller does not have to
observe the notification itself just to get its stream back. Only
streams the interruption stopped resume; one the caller had paused
stays paused.

Confirmed on device: an app pointed at this branch, with its own
restart workaround and its interruption observer both removed,
recovers its audio after an alarm is dismissed.
- Replace the playing/interrupted bool pair with a PlaybackState enum,
  so pause() during an interruption can't leave a stale flag that
  restarts the stream on the next interruption end.
- Narrow unsafe to the extern-static reads that actually need it.
- Drop the redundant field comment, tighten changelog wording.

Co-authored-by: Benoît Rouleau <benoit.rouleau@icloud.com>
@roderickvd
roderickvd force-pushed the ios-audio-session-interruption-review branch from 1e9734e to 1361cfc Compare July 30, 2026 17:47
@roderickvd
roderickvd merged commit 11014e4 into RustAudio:master Jul 30, 2026
31 checks passed
@roderickvd
roderickvd deleted the ios-audio-session-interruption-review branch July 30, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants