Fix player freeze / detach via audio-focus hardening#26
Merged
Conversation
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]>
Co-Authored-By: Claude Opus 4.8 <[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]>
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.
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:
AudioAttributes.DEFAULT, whoseusageisUNKNOWN. AAOS's strict audio-focus policy grants/returns focus unreliably for an unspecified usage.AUDIOFOCUS_GAIN, ExoPlayer sits withplayWhenReady = truebutplaybackSuppressionReason = 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
USAGE_MEDIA+AUDIO_CONTENT_TYPE_MUSICso AAOS reliably grants/returns focus.playWhenReadytrue, same suppression reason), re-request focus by togglingplayWhenReady. 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.onPlaybackSuppressionReasonChangedand set a Crashlytics custom key, to confirm the diagnosis from real freezes.Verification
./gradlew :automotive:assembleDebugbuilds cleanly.logcat/ Crashlytics will showsuppressionReason=1withplayWhenReady=true, and the watchdog log when it recovers.🤖 Generated with Claude Code