Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[audiofileplayer] onComplete never called #109

Closed
tamoyal opened this issue May 5, 2021 · 2 comments
Closed

[audiofileplayer] onComplete never called #109

tamoyal opened this issue May 5, 2021 · 2 comments

Comments

@tamoyal
Copy link

tamoyal commented May 5, 2021

Is there any situation where onComplete would not be called? I use that callback to clear an important flag and sometimes it is not called even though the audio completes.

Audio? audio;
play() {
final audioData = ...
audio =
        await Audio.loadFromByteData(audioData, onDuration: (duration) async {
      logInfo('onDuration: ${duration}');
      willPlay();

      // https://github.com/google/flutter.plugins/issues/106
      await Future.delayed(const Duration(milliseconds: 100));

      logInfo('Play audio file');
      await audio?.play();
      logInfo('Finished playing audio file');
      await audio?.dispose();
      logInfo('Audio disposed');
    }, onComplete: () {
      logInfo('Audio ON COMPLETE HOOK');
      isPlaying = false;
    }, onPosition: (pos) async {
      onPosition(pos);
    }, onError: (errorMessage) {
      isPlaying = false;
      final error =
          'Audio.loadFromByteData ERROR: $errorMessage';
      logError(error);
      Sentry.captureMessage(error);
    });
}

I also notice that sometimes when this occurs, the audio cuts out early. So if my audio file is 3 seconds, it will just stop playing after 1 second but onComplete is not called, onError is also not called, and there is no exception.

I actually cannot reproduce this locally, it only happens for some of my users. We all have updated OS's (iOS 14.5.1).

Are there scenarios where calling dispose could be an issue? The code above looks right based on examples / docs I've seen

@monkeyswarm
Copy link
Collaborator

I don't have much of a recommendation unless I see a reproducible case.

One tweak is that I would suggest not referring to player from within one of its callback closures (i.e. 'player' in this case)

As I mention in #106 (comment)
you don't need to wait for onDuration to callback in order to start playback. You can just do

audio = Audio.loadFromByteData()..play()..dispose();

Let me know if that changes anything.

@tamoyal
Copy link
Author

tamoyal commented May 6, 2021

True but I need to know the duration for the player animation. Unfortunately I had to ditch the library last night as there were too many bugs so I can't give you a reproducible case ...not that it would help anyway since it only happens on like 25% of our users devices so it's a shot in the dark to begin with. Might be good to add an example in the docs of how you would approach getting the duration before playback as I think that's a common use case? Feel free to close this issue if it's not helpful as I won't be able to give it the love that it needs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants