I am trying to expose media items to other media apps that can browse my app's content through my MediaBrowserServiceCompat
service.
In my onLoadChildren
method I am constructing MediaBrowserCompat.MediaItem
with a MediaDescriptionCompat
that includes a Bundle
that has some extras that I need to play the item.
public class Service extends MediaBrowserServiceCompat {
...
@Override
public void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
val bundle = Bundle().apply {
putString("extra", "some value")
}
MediaDescriptionCompat description = new MediaDescriptionCompat.Builder()
.setMediaId(mediaId)
.setExtras(bundle)
.setTitle("title")
.setSubtitle("subtitle")
.setIconUri(uri)
.build();
MediaBrowserCompat.MediaItem item = new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);
val items = ArrayList<MediaBrowserCompat.MediaItem>()
items.add(item)
result.sendResult(items)
}
So in the onPlayFromMediaId(String mediaId, Bundle extras)
callback that I get when the user has clicked on the item, I am getting the right mediaId
but the extras
is an empty bundle.
private class MediaSessionCallback extends MediaSessionCompat.Callback {
...
@Override
public void onPlayFromMediaId(String mediaId, Bundle extras) {
super.onPlayFromMediaId(mediaId, extras);
//here extras is empty
}
I am sure that the MediaItem has the extras bundle when sent in the Result<List<MediaBrowserCompat.MediaItem>>
result in onLoadChildren
but I am not sure why it is being returned empty. What can cause such an issue?
Thank you!