Skip to content

Release audio session after alarm so other audio is no longer ducked - #806

Open
bjorkert wants to merge 1 commit into
devfrom
fix/alarm-audio-session-release
Open

bjorkert wants to merge 1 commit into
devfrom
fix/alarm-audio-session-release

Conversation

@bjorkert

@bjorkert bjorkert commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

The alarm releases the audio session with notifyOthersOnDeactivation when it is stopped or snoozed and when its last sound finishes, so audio from other apps that was ducked during the alarm returns to full volume right away, also when the app is kept alive in the background by a Bluetooth heartbeat. With Silent Tune holding the session it stays active and goes back to the mixable category Silent Tune uses. Spoken BG uses the same release path, which keeps it from deactivating the session under a playing alarm.

Related to #782.

@marionbarker

marionbarker commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

I asked Claude to review and got an approval with some comments for you to review. Seems like the interaction with Speak BG may be one thing to consider.

Issues

  1. The reverse race isn’t guarded. If an alarm stops or finishes while spoken BG is still talking, releaseAudioSession() tries to deactivate under the speech. That usually fails with an isBusy error, which gets logged, and the release then happens at speech didFinish. It’s harmless in practice, but adding MainViewController.shared?.speechSynthesizer.isSpeaking != true to the guard would make the release logic symmetric.
  2. The Silent Tune branch never deactivates, so other apps are never notified. Changing the category on an active session should stop ducking. But if the alarm activated with [] (Silent Tune or foreground), it interrupted other audio rather than ducking it. Interrupted apps such as a podcast or music player only auto-resume when they receive an interruption-ended notice. A category change doesn’t send one, so for Silent Tune users the other app’s audio will likely stay paused until they press play. That may be acceptable, since you can’t deactivate without losing Silent Tune’s background hold, but the PR description should say so. It’s also the main thing to check on a device.

Minor:
The Speak BG quick action in AppSceneDelegate uses its own synthesizer with no delegate, so it still never releases the session. That isn’t new with this PR, but it’s in the same area if you want to fix it.

@marionbarker marionbarker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successful build. Please read the Claude comments as well.

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.

Volume attenuated after LoopFollow alarm

2 participants