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

[Web, Chrome 92] AudioElement is not getting disposed correctly #966

Closed
Tregan opened this issue Jul 27, 2021 · 1 comment · Fixed by #1516
Closed

[Web, Chrome 92] AudioElement is not getting disposed correctly #966

Tregan opened this issue Jul 27, 2021 · 1 comment · Fixed by #1516
Labels
bug platform-web Affects the web platform

Comments

@Tregan
Copy link

Tregan commented Jul 27, 2021

Chrome 92 has introduced a limit on the number of audio tags that can be allocated per tab. 75 for desktop, 40 for mobile. This causes issues when playing a lot of audio files, since currently the AudioElements are not removed after playing.

Full Description
AudioPlayers currently does not remove created AudioElements from the DOM. This obviously leads to issues when the browser has a hard limit of the number of AudioElements that can be active at once. Even calling setUrl(String url) will cause the issue to pop up eventually, since a new AudioElement is created every time.

I've added a workaround that seems to fix the issue, but I'm not sure this would be the best way to solve it.
In audioplayers_web.dart change release() and start(double position) to the following

void release() {
    player?.src = '';
    player?.remove();
    _cancel();
    player = null;
  }

void start(double position) {
    isPlaying = true;
    if (currentUrl == null) {
      return; // nothing to play yet
    }
    if (player == null) {
      recreateNode();
    }
    player?.play();
    player?.currentTime = position;
    player?.onEnded.listen((event) {
      release();
    });
  }

player?.src = ''; is important, since only calling player?.remove() won't properly destroy the AudioElement.

Code to Reproduce
Easiest way to reproduce is ofcourse to create an app with the latest AudioPlayers (0.19.1), and play a lot of audio using any of the available methods. Personally I'm using AudioCache but as a quick test I'm sure you could do something like

for(int i = 0; i < 100; i++) {
  AudioPlayer().play('assets/audio/sound.mp3');
}

Log Errors
App error:

NotSupportedError: Failed to load because no supported source was found.

Browser error:

[Intervention] Blocked attempt to create a WebMediaPlayer as there are too many WebMediaPlayers already in existence. See crbug.com/1144736#c27

Files/URLs/Sources

  • audioplayers/lib/src/audioplayers_web.dart

Platforms

  • OS: web, Chrome
  • OS version: Chrome 92.0.4515.107
  • Device: physical, Windows 10
  • flutter version: Flutter 2.2.3 stable
  • audioplayers version: 0.19.1
@Tregan Tregan added the bug label Jul 27, 2021
@Gustl22 Gustl22 added the platform-web Affects the web platform label Sep 27, 2022
@Gustl22
Copy link
Collaborator

Gustl22 commented Sep 27, 2022

Is this still a thing in audioplayers: ^1.1.0 ? If yes, do you want to make a PR for this?

Gustl22 pushed a commit that referenced this issue May 23, 2023
# Description

Implement correct `AudioElement` releasing as mentioned in the #966
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug platform-web Affects the web platform
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants