Fix audio focus handling in the TTS navigator - #820
Draft
mickael-menu wants to merge 1 commit into
Draft
Conversation
- TTS playback now pauses on a transient audio focus loss (e.g. a notification or assistant speaking) and resumes automatically when focus is regained. Previously only a permanent loss paused playback. - The handleAudioFocus parameter of Player.setAudioAttributes() is now honored on the player returned by TtsNavigator.asMedia3Player(), letting apps disable the toolkit's automatic focus handling and manage focus themselves. This also fixes apps immediately losing the audio focus they requested to the toolkit's own request. - Playback is no longer started when the audio focus request is denied by the system (e.g. during a phone call). The audiobook navigator is unaffected, as ExoPlayer natively implements both behaviors. Fixes #615 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes two distinct bugs (plus one latent) in
TtsSessionAdapter/AudioFocusManager:handleAudioFocusparameter ofPlayer.setAudioAttributes()was dropped, so the toolkit's own focus request — re-issued on every playback state emission — immediately stole focus back from apps managing it themselves (the reported "focus immediately lost"). It's now honored with ExoPlayer's exact semantics (null attributes → abandon and stop requesting), andgetAudioAttributes()now returns the real attributes.PLAYER_COMMAND_WAIT_FOR_CALLBACK(notification, assistant, duck-on-speech) was a no-op. TTS now pauses on transient loss and resumes automatically on regain; a manual pause during an interruption sticks.updateAudioFocus()was discarded, so playback could start during a phone call; it no longer does. The API-26AudioFocusRequestis also rebuilt when attributes change.The audiobook navigator is unaffected — ExoPlayer natively implements both behaviors.
Needs on-device testing: (1) notification/assistant interruption pauses and resumes TTS; (2) another app's music pauses TTS permanently; (3) opt-out via
setAudioAttributes(attrs, false)lets the app keep focus; (4) TTS doesn't start during a phone call.Fixes #615
🤖 Generated with Claude Code