Repository navigation
Title: Crash on launch — IllegalArgumentException: cannot use a recycled source in createBitmap (MediaMetadata/MediaSession) #2379
Aniket-alpha
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Description
App crashes shortly after launch when setting media session metadata —
specifically while scaling the album art bitmap for MediaMetadata.
Device info
Stack trace
java.lang.IllegalArgumentException: cannot use a recycled source in createBitmap
at android.graphics.Bitmap.createBitmap(Bitmap.java:942)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:864)
at android.media.MediaMetadata$Builder.scaleBitmap(MediaMetadata.java:996)
at android.media.MediaMetadata$Builder.build(MediaMetadata.java:970)
at android.media.session.MediaSession.setMetadata(MediaSession.java:512)
...
Steps to reproduce
metadata setup / album art restoration
Likely cause
The album art bitmap passed to MediaMetadata appears to be recycled
(possibly by the image loader's memory cache) before
MediaMetadata.Builder.build() internally scales it. This is a known
pattern in other Media3-based apps on Android 15's stricter bitmap
memory handling. A defensive bitmap copy before putBitmap() likely
resolves it.
Suggested fix
Copy the bitmap before attaching it to the metadata builder, and
guard against isRecycled():
[paste the toSafeMediaArt() snippet above]
All reactions