flutter_sound icon indicating copy to clipboard operation
flutter_sound copied to clipboard

[BUG]: Regression: startPlayer throws an exception if called when a sound is already playing

Open thandal opened this issue 9 months ago • 8 comments

Flutter Sound Version : ^9.25.9

  • FULL flavor

  • Important: Result of the command : flutter pub deps | grep flutter_sound

Example BAD configuration: $ flutter pub deps | grep flutter_sound ├── flutter_sound 9.28.0 │ ├── flutter_sound_platform_interface 9.28.0 │ ├── flutter_sound_web 9.28.0 │ │ ├── flutter_sound_platform_interface...

GOOD configuration (after downgrading): $ flutter pub deps | grep flutter_sound ├── flutter_sound 9.17.8 │ ├── flutter_sound_platform_interface 9.17.8 │ ├── flutter_sound_web 9.17.8 │ │ ├── flutter_sound_platform_interface...


Severity

  • Result is not what expected

Platforms you faced the error

  • Flutter Web

Describe the bug A clear and concise description of what the bug is.

To Reproduce

  1. play a sound using startPlayer.
  2. before the sound has finished playing, play another sound with startPlayer
  3. An exception is thrown "Exception: Player is not stopped", and the second sound is not played (though the first sound is stopped).

In prior releases, this worked as expected: the old sound stopped and the new sound began to play. From inspecting the code, it looks like startPlayer awaits stop() -- so it seems like this is also the intended behavior.

I downgraded to 9.17.8 and the behavior is as expected again. I haven't figured out exactly when the regression occurred.

Logs!!!!

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 419:5 log │ #1 packages/flutter_sound_web/flutter_sound_player_web.dart 335:13 ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 startPlayer FromURI : https://XXXX └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 1117:13 │ #1 packages/flutter_sound_web/flutter_sound_player_web.dart 345:3 ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 FS:<--- startPlayer └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 342:5 startPlayerCompleted │ #1 packages/flutter_sound_web/flutter_sound_player_web.dart 153:8 ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 ---> startPlayerCompleted: true └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 354:5 startPlayerCompleted │ #1 packages/flutter_sound_web/flutter_sound_player_web.dart 153:8 ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 <--- startPlayerCompleted: true └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 1039:13 │ #1 packages/flutter_sound/public/flutter_sound_player.dart 1031:20 [_startPlayer] ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 FS:---> startPlayer └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 1772:13 │ #1 packages/flutter_sound/public/flutter_sound_player.dart 1771:16 [_stop] ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 FS:---> _stop └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 361:5 stopPlayerCompleted │ #1 packages/flutter_sound_web/flutter_sound_player_web.dart 172:8 ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 ---> stopPlayerCompleted: true └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 376:5 stopPlayerCompleted │ #1 packages/flutter_sound_web/flutter_sound_player_web.dart 172:8 ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 <--- stopPlayerCompleted: true └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 1829:17 ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 Player is not stopped! └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ #0 packages/flutter_sound/public/flutter_sound_player.dart 1836:13 ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ │ 🐛 FS:<--- _stop └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Error while calling startPlayer: Exception: Player is not stopped


thandal avatar Mar 27 '25 18:03 thandal

Thank you for your Problem Report. It is clear and well precise. I am going to look to that tomorrow.

Larpoux avatar Mar 27 '25 18:03 Larpoux

Do you use two Flutter Sound Players or do you have only one ?

Larpoux avatar Mar 27 '25 20:03 Larpoux

Just one on this page -- though I do create other soundPlayers on other pages of my app.

thandal avatar Mar 27 '25 20:03 thandal

Flutter Sound is not coded as to allow several startPlayer() at the same time on a given player. If you want to do that you must create two Flutter Sound players. You probably had an exception that you ignored in the previous versions. The problem we had is that the player was left in an undefined state after an exception. It was a problem, especially with ‘play from stream’. Now, the player is correctly closed when we encounter an exception.

You really must use two different players.

Larpoux avatar Mar 27 '25 21:03 Larpoux

It's hard to argue with the guy who designed the thing, but a few observations:

  1. I have tried to "await player.stopPlayer();" before playing the second sound... And it doesn't work, throws exactly the same exception!
  2. The startPlayer code actually calls "await stopPlayer()" itself right above the error message... and you can see from the logs that it thinks it has stopped ("stopPlayerCompleted: true"). But the next thing in the logs is "Player is not stopped!". Again, stopping doesn't seem to be working correctly!
  3. It worked perfectly before, definitely no exceptions unless they were caught internally to the soundPlayer.

thandal avatar Mar 27 '25 21:03 thandal

Ok,. I am going to look that tomorrow. Sorry for the regression

Larpoux avatar Mar 27 '25 21:03 Larpoux

Yes, you are probably right that there is a bug in Flutter Sound. I was first confused that you was trying to play two files at the same time on a Player. But Flutter Sound closes the previous file if already playing. That has always been like that. That's OK and this is not an undocumented feature. Your code is OK.

It's too bad that you have no idea when the regression occurred. There has been many versions since 9.17.8. This is probably a bug in closePlayer() :

  • either it does not close correctly the player.
  • either it closes correctly the player but returns a bad vale 'isPlaying'.

The problem is that we are 3 guys :

  • you
  • me
  • howler And every body has its own Player state!

Larpoux avatar Mar 28 '25 02:03 Larpoux

I released a new 9.10.5 that may fix your issue. But I am not sure that this patch is not harmful. If you want you can try Taudio 9.10.5. It is really easy to upgrade to Taudio. Just 5 minutes. There is a little guide here to do the upgrade.

Larpoux avatar Mar 28 '25 04:03 Larpoux