有两种方式:
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]);
}