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

Playing multiple audios at the same time.

Open noeljayson opened this issue 2 years ago • 7 comments

Clicking on the next button multiple times it plays multiple audios at the same time

noeljayson avatar Mar 10 '23 11:03 noeljayson

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 avatar Mar 14 '23 13:03 mt633

@mt633 your fork seem to be fix the issue. Please consider creating a PR? This is a major bug

KRTirtho avatar May 05 '23 05:05 KRTirtho

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 avatar May 05 '23 08:05 mt633

@mt633 I'm not actively developing, but if you create a PR, I'll merge it.

kalismeras61 avatar May 05 '23 08:05 kalismeras61

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).

mt633 avatar May 05 '23 09:05 mt633

Thank you @mt633 for the support! Much appreciated

akarapetsas avatar May 16 '23 08:05 akarapetsas

realy a major bug

moshstudio avatar Jun 15 '23 14:06 moshstudio