Flutter-AssetsAudioPlayer icon indicating copy to clipboard operation
Flutter-AssetsAudioPlayer copied to clipboard

[WEB] Error: AbortError: The play() request was interrupted by a call to pause()

Open PawlikMichal25 opened this issue 5 years ago • 3 comments

Flutter Version

Flutter 1.22.1 • channel beta

Lib Version

2.0.10

Platform (Android / iOS / web) + version

Web, any version

Describe the bug

The error is thrown causing the player to stop. It happens when user quickly switches between tracks and clicks play/resume.

The exact error message is:

Error: AbortError: The play() request was interrupted by a call to pause(). https://goo.gl/LdLk22


    at Object.createErrorWithStack (http://localhost:62245/dart_sdk.js:4342:12)
    at Object._rethrow (http://localhost:62245/dart_sdk.js:37882:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:62245/dart_sdk.js:37876:13)
    at Object._microtaskLoop (http://localhost:62245/dart_sdk.js:37708:13)
    at _startMicrotaskLoop (http://localhost:62245/dart_sdk.js:37714:13)
    at http://localhost:62245/dart_sdk.js:33226:9

Small code to reproduce It's hard to reproduce, because it doesn't always happen. However, after reading the article linked in the error message, I'm guessing it has something to do with asynchronous code and not awaiting futures.

Looking at library's code I wonder if eg. play() shouldn't return a Future and be awaited, considering that _audioElement.play(); returns a future?

What do you think?

PawlikMichal25 avatar Oct 13 '20 13:10 PawlikMichal25

Noticed the same. There's also an issue where you try to play an audio file when the user has not interacted with the window yet: NotAllowedError: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD

Currently I fixed both of these by embedding the assets_audio_player_web package in my app and specifying a dependency override:

dependency_overrides:
  assets_audio_player_web:
    path: .embedded_packages/assets_audio_player_web

Then in lib/web/web_player_html.dart change play() to

@override
  void play() {
    if (_audioElement != null) {
      isPlaying = true;
      forwardHandler?.stop();

      _audioElement?.play().catchError((e, s) {
        isPlaying = false;
      });
    }
  }

I doubt this will do as a permanent fix, but for me this works fine for now😛

Tregan avatar Aug 03 '21 08:08 Tregan

@Tregan can you create pr for the fix ?

kalismeras61 avatar Aug 03 '21 08:08 kalismeras61

@Tregan can you create pr for the fix ?

Well I could, but I really don't think this would be the best solution that fits everyone. I don't really have time at the moment to come up with a proper solution 😞

Tregan avatar Aug 03 '21 09:08 Tregan