Open noeljayson opened 1 year ago
I also noticed this issue. I'm not really a Kotlin programmer, but from what I understand the use of GlobalScope
in the open method is the cause of the problem here.
https://github.com/florent37/Flutter-AssetsAudioPlayer/blob/0fcc9c55a35c240ca209c24e601d75863281c6d8/android/src/main/kotlin/com/github/florent37/assets_audio_player/Player.kt#L184
That is not canceled if it's not finished before a new signal to open is sent and the result is two scopes running in parallel. From what I understand you could resolve it by creating your own CoroutineScope
that you cancel if it's not finished before launching a new scope.
I've tried the following approach in open
and it seems to work for me. You can check out the full code here.
try {
stop(pingListener = false)
if (scope.isActive) {
scope.cancel()
scope = MainScope()
}
} catch (t: Throwable) {
print(t)
}
// Lines removed for readability
scope.launch(Dispatchers.Main) {
If anyone with more Kotlin experience is able to see a better approach for it, I'll gladly hear it!
@mt633 your fork seem to be fix the issue. Please consider creating a PR? This is a major bug
I would if this project seemed more alive. Haven't seen any response or active development from the project manager(s) in some time and I don't really want to take the time to create a PR for this if it'll never be merged.
@mt633 I'm not actively developing, but if you create a PR, I'll merge it.
Thanks @kalismeras61, good to know. Then I'll try to find time to create a PR for this (and probably a few other PR for some other bugs/features as well).
Thank you @mt633 for the support! Much appreciated
realy a major bug
Clicking on the next button multiple times it plays multiple audios at the same time