Skip to content

fix(media3): stabilize Android Auto playback and audio focus on 2.2.0 - #21

Open
Kechos23 wants to merge 1 commit into
maxrave-dev:multiplatformfrom
Kechos23:fix/android-auto-audio-focus-resume
Open

Kechos23 wants to merge 1 commit into
maxrave-dev:multiplatformfrom
Kechos23:fix/android-auto-audio-focus-resume

Conversation

@Kechos23

@Kechos23 Kechos23 commented Aug 7, 2026 •

Copy link
Copy Markdown

Summary

Stabilize Android Auto browse/search playback, MediaSession transport, audio-focus handling, queue restoration, and Next/Previous availability with the adapter-owned crossfade player.

This revision is rebased onto the current multiplatform core used by SimpMusic v2.2.0 (0b9ce7b). It supersedes the previous v2.1.0 patch while preserving the same functional intent.

Problems addressed

  • Home and Search selections could leave the previous song paused or make the Android Auto Home page fall back to "Nothing to show".
  • Playback could report PLAYING after process restoration while producing no audio until a different browse item was selected.
  • MediaSession controllers could bypass the adapter-owned audio-focus and playback-intent state.
  • SimpMusic could continue playing alongside another media app instead of yielding on permanent audio-focus loss.
  • Next/Previous availability could remain stale until a natural track transition.
  • Next/Previous could be dispatched twice through both the callback and forwarding-player paths.

Implementation

  • Route synchronous MediaSession transport through CrossfadeExoPlayerAdapter before delegate transport.
  • Require a fresh adapter-level audio-focus request before playback starts and pause on permanent AUDIOFOCUS_LOSS.
  • Preserve playback intent while players and queues are being restored or replaced.
  • Preserve the adapter-owned queue for Android Auto browse/search selections and return the resolved selected media item.
  • Use a safe idle delegate while replacing the active player.
  • Publish available-command changes through batched player events so Android Auto refreshes Next/Previous promptly.
  • Remove duplicate callback dispatch for Next/Previous.
  • Add regression tests for denied-focus gating and intent-before-delegate ordering.

v2.2.0 reconciliation

SimpMusic v2.2.0 now has a stronger upstream queue restoration and onPlaybackResumption implementation. This revision intentionally retains that upstream implementation and removes the older PR's custom resumption override and MediaServiceHandlerImpl restore workaround. Applying the previous v2.1.0 patch unchanged would create two onPlaybackResumption overrides after merging with current multiplatform.

The resulting diff is limited to three Media3 production files and one regression-test file. It contains no app icon, artwork, desktop playback, database, networking, recommendation, or UI changes.

Validation

  • :media3:compileDebugKotlin — passed.
  • :media3:testDebugUnitTest — 12 tests passed, 0 failed.
  • :androidApp:assembleDebug — passed against SimpMusic v2.2.0.
  • Tested with a physical Android phone and Android Auto Desktop Head Unit.
  • Verified Home, Search, and For You selections; prompt Next/Previous availability; force-stop/process restoration; and audio-focus handoff with Metrolist and CarStream.

The tests cover the transport and ordering regressions; broader vehicle, OEM, Cast, and crossfade combinations still benefit from maintainer testing.

Core commit: 3b13369, signed and GitHub-verified. No APK binaries are included in this PR.

@Kechos23
Kechos23 force-pushed the fix/android-auto-audio-focus-resume branch 2 times, most recently from e5b26e0 to 0a4f801 Compare August 7, 2026 13:20
@Kechos23
Kechos23 force-pushed the fix/android-auto-audio-focus-resume branch from 0a4f801 to fc439ae Compare September 7, 2026 21:36
@Kechos23

Kechos23 commented Sep 7, 2026

Copy link
Copy Markdown
Author

Hi @maxrave-dev, I've updated this PR for the core used by SimpMusic v2.1.0 and reconciled it with the upstream transport and restoration changes. The focus remains Android Auto Home/Search selection, queue navigation availability, and consistent playback intent/audio focus through MediaSession.

The Android build and all 12 Media3 unit tests pass, including two new transport regression tests. I've also built an updated APK for device testing and refreshed the description with the scope and validation limitations.

When you have time, could you take a look? Feedback on the forwarding-player/adapter queue ownership approach would be especially helpful. Thank you!

Keep MediaSession transport routed through the crossfade adapter, require fresh audio focus before playback starts, and preserve adapter-owned queues during browse and search selections.

Publish transport command changes promptly, remove duplicate next/previous dispatch, and cover denied-focus and synchronous transport ordering with regression tests.
@Kechos23
Kechos23 force-pushed the fix/android-auto-audio-focus-resume branch from fc439ae to 3b13369 Compare September 27, 2026 03:15
@Kechos23 Kechos23 changed the title fix(media3): stabilize Android Auto playback and audio focus fix(media3): stabilize Android Auto playback and audio focus on 2.2.0 Sep 27, 2026
@Kechos23

Copy link
Copy Markdown
Author

Updated this PR onto the current multiplatform core used by SimpMusic v2.2.0.

The functional fixes remain focused on Android Auto selection, adapter-owned queues, MediaSession transport, audio focus, restoration, and Next/Previous command refresh. The v2.1.0-only MediaServiceHandlerImpl workaround and custom onPlaybackResumption override have been removed in favor of the stronger upstream v2.2.0 restoration path.

The replacement commit is SSH-signed and GitHub-verified. Compile, all 12 Media3 tests, and the Android debug build pass, and the updated build was exercised on a physical phone with Android Auto DHU, including Home/Search/For You playback, restore behavior, and focus handoff with other media apps.

When you have time, could you please review the updated v2.2.0-compatible diff? Thank you.

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