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