颤抖的文件播放列表

时间:2020-03-12 20:09:46

标签: flutter audio dart

我正试图一个接一个地播放文件列表,但是文件一起播放,有人可以帮忙吗?

我正在为此使用库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;

1 个答案:

答案 0 :(得分:1)

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;