我试图一个接一个地播放文件列表,但它会一起播放,有人能帮忙吗?
我正在为使用库AudioPlayers
感谢
case 2: {
//statements;
for(int i = 0; i < letterList1().length; i++){
String file = letterList1()[i]['audio'];
advancedPlayer = await player.play(file);
if(advancedPlayer.state == AudioPlayerState.PLAYING){
advancedPlayer.onPlayerCompletion.listen((onDone) async {
advancedPlayer.state = AudioPlayerState.COMPLETED;
});
}
playingFile = file;
}
}
break;
case 1: {
//statements;
for(int i = 0; i < letterList1().length; i++){
String file = letterList1()[i]['audio'];
advancedPlayer = await player.play(file);
playingFile = file;
while(advancedPlayer.state == AudioPlayerState.PLAYING){
print("while: ${advancedPlayer.state}");
await Future.delayed(Duration(seconds: 1));
print(i);
if(advancedPlayer.state == AudioPlayerState.PLAYING){
advancedPlayer.onPlayerCompletion.listen((onDone) async {
print("object");
player.clear(file);
advancedPlayer.state = AudioPlayerState.COMPLETED;
await advancedPlayer.stop();
});
}
if(advancedPlayer.state == AudioPlayerState.COMPLETED){
print("if: ${advancedPlayer.state}");
await advancedPlayer.stop();
break;
}
}
}
}
break;