android / uamp

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

How can i set a drawable file in MediaItem in automotive app? #510

Closed thivankasarathchandra closed 1 year ago

thivankasarathchandra commented 1 year ago

I modified following code to set a simple MediaItem one Browsable and one playable. But Still it shows a system default art image.

@Override
public void onLoadChildren(final String parentMediaId, final Result<List<MediaBrowser.MediaItem>> result) {
    // Return the children of the given parent media item
    List<MediaBrowser.MediaItem> children = getChildren(parentMediaId);
    result.sendResult(children);
}  
private List<MediaBrowser.MediaItem> getChildren(String parentId) {
    int drawableResourceId = R.drawable.finallogo;
    Uri drawableUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
            + "com.examole.app" + "/" + drawableResourceId);
    List<MediaBrowser.MediaItem> children = new ArrayList<>();
    if (parentId.equals("root")) {
 children.add(new MediaBrowser.MediaItem(new MediaDescription.Builder()

                .setMediaId("media_item_1")
                .setTitle("Browsable Item")
                .setSubtitle("test")
                .setIconUri(drawableUri)
                .build(),MediaBrowser.MediaItem.FLAG_BROWSABLE ));
    }else{
        children.add(new MediaBrowser.MediaItem(new MediaDescription.Builder()
            .setMediaId("media_item_1")
            .setTitle("Playable Item")
            .setSubtitle("test2")
                .setIconUri(drawableUri)
            .build(), MediaBrowser.MediaItem.FLAG_PLAYABLE));
    }
    return children;
    }

Can Someone please please help me on this issue. And there are no many examples for Automotive OS out there either. I would Love to know what is going on.

thivankasarathchandra commented 1 year ago

Never mind of content resolver. if you using a local drawable just use this metadata.putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, "android.resource://com.examplea.app/drawable/image");