0

I have a generic Android Automotive OS emulator running. I created a sample automotive app that should show 6 songs at the main browsable root. The code snippet in my MediaBrowserService is:

    override fun onLoadChildren(parentId: String, result: Result<MutableList<MediaItem>>) {
        val mediaList = ArrayList<MediaItem>()

        if (parentId == "root") {
            AUTO_SOURCES.forEach { mediaList.add(buildMediaItem(it.sourceId, it.sourceName)) }
        }

        result.sendResult(mediaList)
    }

    private fun buildMediaItem(mediaId: String, title: String): MediaItem {
        val desc = MediaDescriptionCompat.Builder()
            .setMediaId(mediaId)
            .setTitle(title)
            .setIconUri(mediaId.asAlbumArtContentUri())
            .build()

        return MediaItem(desc, MediaItem.FLAG_PLAYABLE)
    }

I see onLoadChildren being called and the corresponding sendResult however the playable media items are never displayed. If I change them to MediaItem.FLAG_BROWSABLE they display correctly. Any idea what I'm doing wrong?

William Seemann
  • 3,440
  • 10
  • 44
  • 78
  • Looks like the flag is mandatory. E.g. See: http://androidxref.com/9.0.0_r3/xref/packages/apps/Car/LocalMediaPlayer/src/com/android/car/media/localmediaplayer/LocalMediaBrowserService.java#82 – Andrey Samoilov Jul 14 '20 at 16:58
  • @AndreySamoilov thanks for the reply, but can you elaborate? I'm adding the MediaItem.FLAG_PLAYABLE flag. Are you reffing to a different one? – William Seemann Jul 14 '20 at 20:12
  • I mean MediaItem.FLAG_BROWSABLE looks like mandatory to browse. I have viewed AOSP using for both flags (MediaItem.FLAG_BROWSABLE and MediaItem.FLAG_PLAYABLE). See http://androidxref.com/9.0.0_r3/xref/frameworks/base/media/java/android/media/browse/MediaBrowser.java#754 According with these comment i think that: FLAG_BROWSABLE should be used for BrowserCallback. MediaItem.FLAG_PLAYABLE should be used for query in MediaPlayback. – Andrey Samoilov Jul 14 '20 at 21:38

1 Answers1

0

Your builder needs to make a call to setMediaURI

Fracdroid
  • 1,135
  • 10
  • 15