0

第一个参数是inBrowserRoot()的返回类型是什么。onGetroot()MediaBrowserServiceCompat

它的第一个参数是rootId哪个是字符串,那么我要传递专辑的路径吗?我如何获得它的价值?如何返回不为 null 的内容层次结构?

   @Override
   public BrowserRoot onGetRoot(String clientPackageName, int clientUid,
  Bundle rootHints) {


if (allowBrowsing(clientPackageName, clientUid)) {

    return new BrowserRoot(MY_MEDIA_ROOT_ID, null);  // what should I pass here ?
} else {

    return new BrowserRoot(MY_EMPTY_MEDIA_ROOT_ID, null);
}
}

任何帮助表示赞赏。

4

1 回答 1

0

我使用“根”。使用任何字符串,然后在加载子项中,检查父 id 是“root”还是艺术家或专辑 id,然后相应地传递媒体项目

为清楚起见,编辑以从我的 onLoadChildren 添加一些代码(注意,哈希图可以是列表,我使用哈希图使用映射到艺术家/专辑名称的媒体 ID 轻松设置工具栏文本):

    ArrayList<MediaBrowserCompat.MediaItem> media_items = new ArrayList<>();
    HashMap<String, String> artist_ids = MusicLibrary.getListOfArtistIds(getApplicationContext());
    HashMap<String, String> album_ids = MusicLibrary.getListOfAlbumIds(getApplicationContext());

    // Check if this is the root menu:
    if ("root".equals(parentId)) {
        media_items = MusicLibrary.getArtists(context);

    } else if (artist_ids.containsKey(parentId)){
        // parent is artist
        media_items = MusicLibrary.getAlbums(context, parentId);

    } else if (album_ids.containsKey(parentId)){
        // parent is album
        media_items = MusicLibrary.getSongs(context, parentId);

    } 
    result.sendResult(media_items);

您还可以将根变量更改为播放列表并检查它以获取播放列表列表并使用播放列表 ID 列表来获取成员。希望我有所帮助

再次编辑只是为了放入我的 onGetRoot 以显示我的简单:

public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, @Nullable Bundle rootHints) {
    return new BrowserRoot(MusicLibrary.getRoot(), null);
}
于 2020-01-19T06:10:34.497 回答