android / uamp

A sample audio app for Android
Apache License 2.0
13.11k stars 3.76k forks source link

Returns empty bundle on class MediaSessionCompat.Callback#onPrepareFromMediaId in Android Automotive #460

Open albertkhang opened 3 years ago

albertkhang commented 3 years ago

I set the callback for media session in MusicService like this

    mediaSession.setCallback(object : MediaSessionCompat.Callback() {
        override fun onPlayFromMediaId(mediaId: String?, extras: Bundle?) {
            super.onPlayFromMediaId(mediaId, extras)
            val type = extras?.getInt("type", -1)
            val trackNumber = extras?.getInt("MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER", -1)
            Log.i(MusicService::class.java.simpleName, "onPlayFromMediaId type $type, trackNumber: $trackNumber, extras: ${extras.toString()}")
        }
    })

In android auto, I can get bundle with some data in it, but in Android Automotive, it always returns empty.

  1. Why is it happen?
  2. And how can I get data on the bundle on Android Automotive?
dxshindeo commented 2 years ago

Seeing the same problem. Tested on both Polestar 2 (Android 10) and Automotive (Volvo) emulator images.

Seems like the current and only work-around is by concatenating all extras to the mediaId.