Monday, 19 April 2021

Android Auto: How to return a large number of children on loadChildren() of MediaBrowserService?

I am currently trying to implement a MediaBrowserService to build a media app for Android Auto. I followed the official Android Auto documentation (https://developer.android.com/training/cars/media#onLoadChildren) to implement theonLoadChildren function.

Following is a code snippet that I tried to show the content on the Android Auto screen:

override fun onLoadChildren(parentId: String, result: Result<MutableList<MediaBrowserCompat.MediaItem>>) {
  ...
  if (parentId == NODE_LIBRARY_ALBUMS) {
    val items = mutableListOf<MediaBrowserCompat.MediaItem>()

    val albumList = LibraryManager.getAlbumList()
    for (it in albumList) {
      val descriptionBuilder = MediaDescriptionCompat.Builder()
        .setTitle(it.albumName)
      items.add(MediaBrowserCompat.MediaItem(descriptionBuilder.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE))
    }

    result.sendResult(items)
  }
  ...
}

This works pretty well, when the number of items is small enough. However, when the number of items is large (e.g., about 5,000 items), the following error appears:

E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 1339384)

I found that several other media apps (e.g., Samsung Music) that support Android Auto can show a large number of items. Is there any way to return a large number of items on the onLoadChildren function, or is there any other way to solve this issue?

Thanks!



from Android Auto: How to return a large number of children on loadChildren() of MediaBrowserService?

No comments:

Post a Comment