Skip to content

Fix audio focus handling in the TTS navigator - #820

Draft
mickael-menu wants to merge 1 commit into
developfrom
fix-issue-615
Draft

Fix audio focus handling in the TTS navigator#820
mickael-menu wants to merge 1 commit into
developfrom
fix-issue-615

Conversation

@mickael-menu

Copy link
Copy Markdown
Member

Fixes two distinct bugs (plus one latent) in TtsSessionAdapter / AudioFocusManager:

  • Opt-out ignored: the handleAudioFocus parameter of Player.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), and getAudioAttributes() now returns the real attributes.
  • Transient loss ignored: 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.
  • Denied focus ignored: the result of updateAudioFocus() was discarded, so playback could start during a phone call; it no longer does. The API-26 AudioFocusRequest is 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

- 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>
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.

[Bug] When requesting audio focus to the application, the focus is immediately lost

1 participant