6

Call MediaMetadata.getString, have below crash in report, but not always repro:

 java.lang.RuntimeException: Could not read bitmap from parcel blob.
    at android.graphics.Bitmap.nativeCreateFromParcel(Native Method)
    at android.graphics.Bitmap.access$000(Bitmap.java:32)
    at android.graphics.Bitmap$1.createFromParcel(Bitmap.java:1477)
    at android.graphics.Bitmap$1.createFromParcel(Bitmap.java:1469)
    at android.os.Parcel.readParcelable(Parcel.java:2246)
    at android.os.Parcel.readValue(Parcel.java:2146)
    at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
    at android.os.BaseBundle.unparcel(BaseBundle.java:221)
    at android.os.BaseBundle.getCharSequence(BaseBundle.java:953)
    at android.os.Bundle.getCharSequence(Bundle.java:716)
    at android.media.MediaMetadata.getText(MediaMetadata.java:334)
    at android.media.MediaMetadata.getString(MediaMetadata.java:347)

The code is as blow, the MediaMetadata meta is from the controller of api MediaSessionManager.OnActiveSessionsChangedListener, it should be created by third-part music app.

    meta.getString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST);
    meta.getString(MediaMetadata.METADATA_KEY_ARTIST);            
    meta.getString(MediaMetadata.METADATA_KEY_AUTHOR);         
    meta.getBitmap(MediaMetadata.METADATA_KEY_ART);
    meta.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);            
    meta.getString(MediaMetadata.METADATA_KEY_ALBUM);
    meta.getString(MediaMetadata.METADATA_KEY_TITLE);

Why the getString will parse the bitmap? is it possible the memory is out when this happen?

Sarah Ma
  • 141
  • 1
  • 6

1 Answers1

0

I think this happens when you put big bitmaps into the MediaMetaData object with .putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, icon). This bitmap is used on the MediaDescription and thus it should be pretty small as it's serialized. It's actually deserialized every time you call getString on the meta data.

So, the solution to this issue would be to only use small bitmaps for METADATA_KEY_DISPLAY_ICON or not use it at all if possible.

Jonas Lüthke
  • 1,480
  • 10
  • 11