【问题标题】:Return type of onGetroot() method of MediaBrowserServiceCompat?MediaBrowserServiceCompat 的 onGetroot() 方法的返回类型?
【发布时间】:2019-12-28 07:28:07
【问题描述】:

BrowserRoot() 的第一个参数是什么,它是MediaBrowserServiceCompatonGetroot() 的返回类型。

它的第一个参数是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);
}
}

感谢任何帮助。

【问题讨论】:

    标签: android android-mediaplayer mediabrowserservicecompat


    【解决方案1】:

    我使用“根”。使用任何字符串,然后在加载子项中,检查父 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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      相关资源
      最近更新 更多