我需要在播放列表上的音轨之间设置特定的时间延迟。前任。10 秒延迟。我怎么能做到这一点?提前致谢
问问题
36 次
1 回答
0
有两种方法:
- 创建所需持续时间的无声音轨,并将其插入到
ConcatenatingAudioSource
. - 不要使用
ConcatenatingAudioSource
,编写自己的播放列表逻辑。
第二种方法的一个例子可能是:
// Maintain your own playlist position
int index = 0;
// Define your tracks
final tracks = <IndexedAudioSource>[ ... ];
// Auto advance with a delay when the current track completes
player.processingStateStream.listen((state) async {
if (state == ProcessingState.completed && index < tracks.length) {
await Future.delayed(Duration(seconds: 10));
// You might want to check if another skip happened during our sleep
// before we execute this skip.
skipToIndex(index + 1);
}
});
// Make this a method so that you can wire up UI buttons to skip on demand.
Future<void> skipToIndex(int i) {
index = i;
await player.setAudioSource(tracks[index]);
}
于 2021-09-12T16:41:14.090 回答