florent37 / Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
https://pub.dartlang.org/packages/assets_audio_player
Apache License 2.0
752 stars 357 forks source link

playlistFinished event is triggering onData even before the song has completed #805

Open ishitajoshi-splash opened 1 year ago

ishitajoshi-splash commented 1 year ago

Flutter Version

My version : 3.3.10

Lib Version

My version : 3.0.6

Platform (Android / iOS / web) + version

Platform : web

Describe the bug playlistFinished is calling onData function before the audio is finished.

Small code to reproduce

//Stop speaking once the audio is finished
    AssetsAudioPlayer player = AssetsAudioPlayer.newPlayer();

      player?.open(Audio.network(audioPath), autoStart: true);
      player?.playlistFinished.listen((finished) {
        print("[log][audio] finished: $finished audio: : $audioPath");

        if (finished == true) {
          audioPlayerCallback(splashRiveVm);
          setState(() {
            audioReadyToPlay = false;
          });
        }
      }, 
      onDone: () {
        print('done');
         audioPlayerCallback(splashRiveVm);
          setState(() {
            audioReadyToPlay = false;
          });
      },

      onError: (error) {
        print('[log][audio][error]$error');

        GlobalExceptionHandler().reportError(error, StackTrace.current);
        audioPlayerCallback(splashRiveVm);
      });