fix: album art missing for same-album tracks over Bluetooth on Tesla (#470)#719
Open
chunjiw wants to merge 2 commits into
Open
fix: album art missing for same-album tracks over Bluetooth on Tesla (#470)#719chunjiw wants to merge 2 commits into
chunjiw wants to merge 2 commits into
Conversation
…dyizm#470) Media3's MediaSessionLegacyStub pushes track metadata to the legacy/AVRCP bridge with a null bitmap whenever the BitmapLoader future isn't already done, then pushes again once the bitmap finishes loading. The default BitmapLoader always resolves asynchronously, so this null-first push happens on every track change. Tesla redraws on a different-album bitmap but dedups the byte-identical bitmap of a same-album track, leaving those tracks with no art. Add SyncBitmapLoader, which returns an already-completed future on LRU cache hits (and decodes inline), so Media3 takes its synchronous branch and the first setMetadata already carries the bitmap. Queue artwork is prewarmed in onTimelineChanged so the cache is populated before the user advances. Registered via MediaLibrarySession.Builder.setBitmapLoader(); the change is additive and modifies no Media3 internals. Co-Authored-By: Claude Opus 4.8 <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.
Problem
On a Tesla (phone paired over Bluetooth), album art is shown only for the first track of an album. Every following track on the same album shows no art. Switching to a track from a different album restores the art; returning to the same album drops it again. Reproducible every time.
Root cause
Album art reaches the car over AVRCP/BIP, which the app feeds indirectly through Media3's
MediaSession. On a track change,MediaSessionLegacyStub.updateMetadataIfChangedloads the artwork via aBitmapLoaderand pushes metadata to the legacy/AVRCP bridge roughly like this (media3 1.8.0, L1628–1704):The default
BitmapLoaderalways resolves on a background thread, soisDone()isfalsewhen Media3 checks it. Every track change therefore pushes metadata twice: once immediately with anullbitmap, then again with the real bitmap once it finishes loading.nullpush, the car's dedup (AVRCP image-handle caching / BIP) treats the identical bytes as "nothing changed" and draws nothing.For comparison, DSub2000 (a Subsonic client that works on Tesla) attaches the bitmap synchronously per track and never produces the null-first push.
Fix
Add a custom
BitmapLoader(SyncBitmapLoader) so thatisDone()istrueon the first check. Media3 then takes its synchronous branch and the firstsetMetadataalready carries the bitmap — the intermediatenullstate never leaves the phone.loadBitmap(uri)checks an LRU cache and returns an already-completed future on a hit; falls back to async loading on a miss.decodeBitmap(bytes)decodes inline and returns an immediate future.onTimelineChanged: when the queue changes, artwork for every queued item is fetched in the background, so the bitmap is almost always cached before the user advances to the next track.Registered via
MediaLibrarySession.Builder.setBitmapLoader(...).The change is additive and does not modify any Media3 internals. The library's null-first code path still exists; the inputs we hand Media3 simply land in the
isDone() == truebranch, so that path is not reached.Scope
SyncBitmapLoader.ktBaseMediaService.kt(+15 lines): build and register the loader, prewarm inonTimelineChanged, shut down the executor inonDestroy.Testing
Tested on a Tesla Model 3 over Bluetooth for several weeks. Album art now displays for every track, including consecutive same-album tracks. No regressions observed for notification, lock-screen, or Android Auto artwork.
Fixes #470.