我需要设置播放列表中音轨之间的特定时间延迟。例:延迟10秒。我怎样才能做到这一点?提前感谢
有两种方法:
- 创建所需持续时间的无声音轨,并将其插入
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]);
}