Android Automotive OS not displaying playable MediaItem's

569 Views Asked by At

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?

1

There are 1 best solutions below

1
On

Your builder needs to make a call to setMediaURI