Skip to content

Fix player freeze / detach via audio-focus hardening#26

Merged
chamika merged 5 commits into
mainfrom
fix-audio-focus-freeze
Jun 28, 2026
Merged

Fix player freeze / detach via audio-focus hardening#26
chamika merged 5 commits into
mainfrom
fix-audio-focus-freeze

Conversation

@chamika

@chamika chamika commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Problem

The ExoPlayer occasionally freezes and the app becomes "detached" from the media session — switching playlist/track does nothing, and the only recovery is to play media from another app (e.g. Spotify) and reopen DashTune.

Root cause

That workaround is the diagnostic tell: the session is alive and receiving commands, but playback is stuck in audio-focus suppression. Two contributors:

  1. The player was built with AudioAttributes.DEFAULT, whose usage is UNKNOWN. AAOS's strict audio-focus policy grants/returns focus unreliably for an unspecified usage.
  2. When a transient focus loss (nav prompt, chime, another app briefly grabbing focus) never receives the matching AUDIOFOCUS_GAIN, ExoPlayer sits with playWhenReady = true but playbackSuppressionReason = TRANSIENT_AUDIO_FOCUS_LOSS. The player looks alive and updates metadata, but produces no sound and won't advance. Playing another app forcibly reassigns focus and unsticks it.

Fix

  • Explicit audio attributes: USAGE_MEDIA + AUDIO_CONTENT_TYPE_MUSIC so AAOS reliably grants/returns focus.
  • Focus-recovery watchdog: on a transient focus-loss suppression, arm an 8s timer; if still stuck (playWhenReady true, same suppression reason), re-request focus by toggling playWhenReady. Safe — if another app legitimately holds focus the re-request is simply denied and we stay suppressed (no double audio); if the state was stale, playback resumes.
  • Diagnostics: log onPlaybackSuppressionReasonChanged and set a Crashlytics custom key, to confirm the diagnosis from real freezes.

Verification

  • ./gradlew :automotive:assembleDebug builds cleanly.
  • On-device: play music, trigger interruptions (nav prompts / another audio app), and confirm playback resumes instead of freezing. If a freeze recurs, logcat / Crashlytics will show suppressionReason=1 with playWhenReady=true, and the watchdog log when it recovers.

🤖 Generated with Claude Code

chamika and others added 5 commits June 28, 2026 23:59
Players occasionally froze with the app detached from the media session:
switching track did nothing and the only fix was to play another app
(e.g. Spotify) and reopen DashTune. That workaround is the tell — the
session is alive but playback is stuck in audio-focus suppression.

Causes addressed:
- Player was built with AudioAttributes.DEFAULT (usage UNKNOWN). AAOS's
  strict focus policy grants/returns focus unreliably for that. Use
  explicit USAGE_MEDIA / AUDIO_CONTENT_TYPE_MUSIC instead.
- No recovery when a transient focus loss never receives the matching
  AUDIOFOCUS_GAIN: the player sits with playWhenReady=true but suppressed,
  looking frozen. Add an 8s watchdog (focusRecovery) that re-requests
  focus by toggling playWhenReady; safe because a denied re-request just
  stays suppressed (no double audio).
- Add WAKE_MODE_NETWORK (+ WAKE_LOCK permission) so streaming doesn't
  stall when the system dozes.

Also logs onPlaybackSuppressionReasonChanged + a Crashlytics custom key to
confirm the diagnosis from real freezes.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The AAOS head unit stays powered while running, so the wake mode is
effectively a no-op there. Keep only the audio-focus fixes (explicit
media attributes + transient-loss recovery), which address the freeze.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Fixes player freezes, the wrong song showing on the player screen, and an offline playback error

Full release notes:

- Fix the player occasionally freezing and becoming unresponsive after an audio interruption (e.g. a navigation prompt), where playback could no longer be controlled
- Fix the Now Playing screen occasionally showing a different (previous) track than the one actually playing
- Fix a playback error that could occur when playing downloaded tracks offline
The release commit should ride along with the checked-out feature branch
(not be made directly on main), so not-yet-merged branch changes are part
of the release and reflected in the notes.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@chamika chamika merged commit d9c7103 into main Jun 28, 2026
1 check passed
@chamika chamika deleted the fix-audio-focus-freeze branch June 28, 2026 23:32
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.

1 participant