audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

Hot restarts continues playing old players

Open stx opened this issue 2 years ago • 5 comments

Files continue to play after hot restarting on the web. There appears to be no way to release or stop the previous player, even if you save the player ID and reference it with stop()/release() after restart.

The net effect of this is if you are playing a music file and hot restart, it will overlap and play twice at the same time.

Is there a workaround?

stx avatar May 07 '22 08:05 stx

The same problem on MacOS!

rimidalv avatar Feb 02 '23 08:02 rimidalv

This is a limitation of Flutter, not of AudioPlayers at the moment: see here and here. Thx @spydon

Edit: As a workaround, stop and start the application completely.

Gustl22 avatar Feb 13 '23 23:02 Gustl22

@Gustl22 https://github.com/flutter/flutter/issues/10437#issuecomment-1937235204 - seems like there is a way to handle hot-restart detecting. Not sure how ideal approach it is and whether it fits audioplayers' case but I guess it's worth taking a look

lkster avatar Apr 09 '24 19:04 lkster

This is a limitation of Flutter, not of AudioPlayers at the moment: see here and https://github.com/flutter/flutter/issues/10437.

I don't think its fair to completely chalk this issue up to Flutter. The root issue might be Flutter, but that lack of a reasonable work around is definitely a limitation of this plugin, not Flutter.

The reason this problem exists is because platform code runs in a single session when Dart code in the Flutter app closes out one session and starts another. The platform code has plenty of opportunity to track what it's doing across hot restarts and provide reasonable controls of those things.

Edit: As a workaround, stop and start the application completely.

This workaround is really bad. This plugin is breaking a core Flutter development behavior just because somebody tries to use this plugin.

Notice the following part of the initial post "There appears to be no way to release or stop the previous player, even if you save the player ID and reference it with stop()/release() after restart."

Why isn't this plugin retaining knowledge of player IDs and allowing hot restart sessions to re-connect to the existing players? That's not a Flutter issue, it's a plugin issue, and it's really impacting the feasibility of engaging in meaningful app development with this plugin.

Personally, I just got done trying a bunch of different approaches to stop repeating the audio every time I hot restart. I thought that surely any audio player plugin would provide a mechanism for doing that. But it appears this one doesn't. I think it's a pretty big deal, and possibly a deal breaker if I can find another audio player for Mac.

UPDATE: I just tried just_audio - it seems to stop audio playback on hot restart without any special intervention. I don't know how its overall feature-set compares to audioplayers but it seems to have enough for my needs, plus hot restart support.

matthew-carroll avatar May 02 '24 23:05 matthew-carroll

@matthew-carroll Look, I'd also love to get this issue fixed, but we are limited to our contributors and their contributions. Currently I'm the only one regularly contributing to this repo, and I, like many other open source enthusiasts, do this for free. If only one of a thousand users would regularly contribute, we could split the work to 45 people.

but that lack of a reasonable work around is definitely a limitation of this plugin, not Flutter.

Going through the issue back then, I concluded that there's no default mechanism from the Flutter side to track hot restarts. And that still has not changed, as the issue is still not resolved. For me personally my priority is not to spend time in a workaround. That doesn't mean there isn't one.

I'd rather fix the original issue at Flutter and then adapt it here, which I already do for other parts of this lib. But this takes time.

I just tried just_audio - it seems to stop audio playback on hot restart without any special intervention.

This library is open source, and we are happy to see more PRs from the community. Pointing to other libraries is not engaging spending time to get this issue fixed.

Why isn't this plugin retaining knowledge of player IDs and allowing hot restart sessions to re-connect to the existing players?

As said, we are happy for any contributions. Thanks for the proposal :)

Gustl22 avatar May 03 '24 06:05 Gustl22