I noticed that if you're playing a song and you do a cold restart during development playbackState is lost. Would be nice if it worked like it does with hot reload.
Changing classification to a feature request.
Is there a way to call AudioPlayer.dispose() internally to the package on cold restart? (As a possible solution.) That would be an ideal solution, imho.
Can you clarify what you mean by a "cold refresh"?
To the best of my knowledge there are three ways to refresh/reload a flutter app.
1) quit & launch the flutter app
2) perform a cold restart (i said refresh by mistake) <<<<
3) perform a hot reload
Can you clarify what you mean by cold restart for both iOS and Android? And also what you mean by quit? Apologies if you have a standard definition in mind, but I can think of a few different ways to interpret this.
In VSCode with DartCode extension.

Said another way, if you hit that green restart button the audio keeps playing and the state doesn't reflect the actual native player state. Ideally the native player state would be reset when you hit the green restart button.
Said yet another way, I expect the audio to stop playing when I restart the app using that green restart button.
Excuse my ignorance, but what exactly do the cold restart and quit buttons do? (I'm not a VSCode user)
Here's how they map
from flutter run
Flutter run key commands.
r Hot reload. 馃敟馃敟馃敟
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
|my phrase | vscode icon | flutter run commands|
|------------|-------------|-------------------------|
|hot reload | yellow lightning bolt | (r) hot reload|
|cold restart | green refresh | (R) hot restart|
|quit | red square | (q) quit|
Ideally what I would like to happen on a hot restart is that the playback state is reset, and the audio resources used on the platform side are also disposed of (so that the audio stops). I'm not aware of any plugin callback that I can implement to do this, and Flutter's plugin API is still evolving and becoming more flexible over time, so one day this may be possible.
Keeping the audio playback going after a hot restart, and then trying to have the playbackState reflect that after a hot restart does not seem compatible with the purpose of hot restart which is to clear the app state completely.
Quit should stop the audio on Android already, but I'm not sure if there is a way to handle this on iOS yet. But if you are aware of a way to do it, let me know and I'd be happy to implement it.
Quit stops the audio on both android and iOS to the best of my knowledge.
This may be a flutter/flutter issue?
Probably. There's a chance there is a plugin API I don't know about, but if not, then I'll need them to add a plugin lifecycle hook that allows me to cleanly dispose of platform resources on a hot restart.
flutter/flutter feature request has been made here https://github.com/flutter/flutter/issues/62678
Thanks for posting it. Hopefully there is already an API that exists which they will point to, otherwise it will go into their back log and probably materialise by next year or later given they probably have higher priorities, but it is good to get the ball rolling.
I'm also interested in this as my users are complaining about the audio that never stops.
@Skyost , Do your users use hot restart? I am surprised about that since hot restart is something that is only accessible in a development environment.
@ryanheise Nop ah ah. But I was just wondering if a fix to this issue will work for my users who are facing the problem I've described above (as it seems to be similar).
Since it's not the same issue, you will need to open a new issue with the details, if indeed it is a bug. A bug would be if you called stop or pause or dispose and the audio kept playing. If it kept playing because you didn't call one of these methods, then that is not a bug. Note that I will mark my reply and yours as off topic so as to keep this issue on topic.
Any one got any luck?
I was trying to use reassemble method
Called whenever the application is reassembled during debugging, for example during hot reload.
But I have not been able to get it working. It would be helpful only if this method could be used to stop all the music being played at hot reload (which we use only in debugging).
That's interesting. What I would need in the plugin is a platform-side solution.
This looks like it might have potential: https://api.flutter.dev/javadoc/io/flutter/embedding/engine/FlutterEngine.html#addEngineLifecycleListener-io.flutter.embedding.engine.FlutterEngine.EngineLifecycleListener-
@ryanheise
For the cold restart (I've always called it hot restart/hot reload), there is no way on the dart side to know when this occurs. The native plugin code has to hold its own references and then dispose of any old resources when the plugin is initialized a second time. I'm happy to implement on the Android side, and I could do it for Swift, but my Obj-C is not good enough...
The reassemble approach works for hot reload, and each developer could manage that on their own by keeping resources alive, or by calling dispose and then reinitializing.
Most helpful comment
flutter/flutterfeature request has been made here https://github.com/flutter/flutter/issues/62678