1

我需要在播放列表上的音轨之间设置特定的时间延迟。前任。10 秒延迟。我怎么能做到这一点?提前致谢

4

1 回答 1

0

有两种方法:

  1. 创建所需持续时间的无声音轨,并将其插入到ConcatenatingAudioSource.
  2. 不要使用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 回答