简体   繁体   English

MediaDescription.Builder() 未设置 MediaItem 图标

[英]MediaDescription.Builder() not setting MediaItem Icon

This is a android automotive media application that uses the MediaBrowserService and i'm trying to set MediaItem MediaDescription Icon using a image in drawable folder.这是一个 android 汽车媒体应用程序,它使用 MediaBrowserService,我正在尝试使用可绘制文件夹中的图像设置 MediaItem MediaDescription 图标。

This is the code I'm Using,这是我正在使用的代码,

@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;
}

The documentation states,文件指出,

Artwork for media items must be passed as a local URI using either ContentResolver.SCHEME_CONTENT or ContentResolver.SCHEME_ANDROID_RESOURCE.媒体项目的插图必须使用 ContentResolver.SCHEME_CONTENT 或 ContentResolver.SCHEME_ANDROID_RESOURCE 作为本地 URI 传递。 This local URI must resolve to either a bitmap or a vector drawable in the application's resources.此本地 URI 必须解析为 bitmap 或应用程序资源中的矢量可绘制对象。 For MediaDescriptionCompat对于 MediaDescriptionCompat

and this code already uses ContentResolver,并且这段代码已经使用了 ContentResolver,

 Uri drawableUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
            + "com.examole.app" + "/" + drawableResourceId);

Does the image needs to be cashed even before loading from local drawable folder?图像是否需要在从本地可绘制文件夹加载之前进行兑现? or can someone specify a way to set local drawable image to media item with onLoadChidren method.或者有人可以指定一种方法来使用 onLoadChidren 方法将本地可绘制图像设置为媒体项。 Thank you.谢谢你。

If it is a file from drawable use this code.如果它是来自 drawable 的文件,请使用此代码。

metadata.putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, "android.resource://com.example.app/drawable/image");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM