我正在阅读audio_service flutter的文档,并在分析mediaLibray时浏览了几个示例,我对AudioService.browsableRootId有疑问,它是什么?它表示任何特定的专辑吗?如果是,那么为什么在AudioService.browsableRootId下的mediaitem的id属性中是一个不是URL的字符串?我是个新手。
代码的示例url=https://github.com/ryanheise/audio_service/blob/7a29ba22fed8567996db1050f58e2d685ef7b713/audio_service/example/lib/example_playlist.dart#L652
class MediaLibrary {
static const albumsRootId = 'albums';
final items = <String, List<MediaItem>>{
AudioService.browsableRootId: const [
MediaItem(
id: albumsRootId,
title: "Albums",
playable: false,
),
],
albumsRootId: [
MediaItem(
id: 'https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3',
album: "Science Friday",
title: "A Salute To Head-Scratching Science",
artist: "Science Friday and WNYC Studios",
duration: const Duration(milliseconds: 5739820),
artUri: Uri.parse(
'https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg'),
),
MediaItem(
id: 'https://s3.amazonaws.com/scifri-segments/scifri201711241.mp3',
album: "Science Friday",
title: "From Cat Rheology To Operatic Incompetence",
artist: "Science Friday and WNYC Studios",
duration: const Duration(milliseconds: 2856950),
artUri: Uri.parse(
'https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg'),
),
MediaItem(
id: 'https://s3.amazonaws.com/scifri-segments/scifri202011274.mp3',
album: "Science Friday",
title: "Laugh Along At Home With The Ig Nobel Awards",
artist: "Science Friday and WNYC Studios",
duration: const Duration(milliseconds: 1791883),
artUri: Uri.parse(
'https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg'),
),
],
};
}
这是一个特定于Android的功能,可与getChildren(parentMediaId)
方法配合使用。当用户想要浏览您的内容并查看由parentMediaId
标识的特定文件夹中的子项列表时,Android Auto将查询getChildren(parentMediaId)
方法。该分层文件夹结构的根由特殊的父IDAudioService.browsableRootId
给出。
audio_service没有提供任何关于Android Auto的文档,因此如果您想使用此功能,最好熟悉原始的Android Auto文档,其中这两个概念由其本地方法名称onGetRoot
和onLoadChildren
引用。例如。https://developer.android.com/training/cars/media
还有一个Android功能使用了相同的getChildren
(onLoadChildren
(方法,那就是媒体会话恢复。有关此方面的更多信息,您可以阅读:https://developer.android.com/guide/topics/media/media-controls