BrowserRoot()的第一个参数是什么,它是MediaBrowserServiceCompat中onGetroot()的返回类型。
它的第一个参数是rootId,这是一个字符串,所以我要传递我的相册的路径吗?我该如何获取它的价值?如何返回非空的内容层次结构?
@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);
}
}任何帮助都是非常感谢的。
发布于 2020-01-19 14:10:34
我使用"root“。使用任何字符串,然后在加载子对象中,检查父id是"root“还是艺术家或专辑id,然后相应地传递媒体项。
为了清晰起见,对我的onLoadChildren进行了编辑,添加了一些代码(请注意,哈希图可以是列表,我可以使用哈希图通过映射到艺术家/专辑名称的媒体i轻松设置工具栏文本):
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);您还可以将root变量更改为playlist,并对其进行检查,以获得播放列表列表,并使用播放列表ids列表来获取成员。希望我能帮上忙
再次编辑,只是为了放入我的onGetRoot,以显示我的是多么简单:
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, @Nullable Bundle rootHints) {
return new BrowserRoot(MusicLibrary.getRoot(), null);
}https://stackoverflow.com/questions/59508947
复制相似问题