颤振只是音频如何改变ConcatenatingAudioSource foreach循环



我想动态地使用for循环来连接来自资产或目录的音频源,而不是通过显示所有音频源来硬编码。
下面的代码显示所有的音频源:

final _playlist = ConcatenatingAudioSource(children: [
AudioSource.uri(
Uri.parse(
"https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3"),
tag: AudioMetadata(
album: "Science Friday",
title: "A Salute To Head-Scratching Science",
artwork:
"https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg",
),
),
AudioSource.uri(
Uri.parse("https://s3.amazonaws.com/scifri-segments/scifri201711241.mp3"),
tag: AudioMetadata(
album: "Science Friday",
title: "From Cat Rheology To Operatic Incompetence",
artwork:
"https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg",
),
),
AudioSource.uri(
Uri.parse("asset:///audio/nature.mp3"),
tag: AudioMetadata(
album: "Public Domain",
title: "Nature Sounds",
artwork:
"https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg",
),
),
]);

那么如何简化代码,以显示只有一个AudioSource.uri(....)与变量使用foreach循环?

' ConcatenatingAudioSource'下的'children'接受一个列表。您可以创建一个单独的函数,循环遍历上面的现有值,或者遍历从另一个地方访问的值,并返回一个列表,然后您可以将该列表传递给"子"。然后你可以这样写:

final _playlist = ConcatenatingAudioSource(children: yourFunction() )

相关内容

  • 没有找到相关文章