question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[check] Multiple SoundPlayers

See original GitHub issue

Flutter Sound Version :

  • Released or Beta version ? Released

  • Version number ? 6.4.8

  • FULL or LITE flavor ? Both (recently switched to lite)

  • Result of the command “flutter pub deps | grep flutter_sound”

|-- flutter_sound_lite 6.4.8+2
|   |-- flutter_sound_platform_interface 6.4.8+2
|   |-- flutter_sound_web 6.4.8+2
|   |   |-- flutter_sound_platform_interface...

Severity

  • Crash ? No

  • Result is not what expected ? Yes

  • Cannot build my App ? No

  • Minor issue ? I’d rate it medium or minor.


Platforms you faced the error

  • iOS ? Yes

  • Android ? Yes

  • Both ? Yes

  • Emulator ? (not tested)

  • Real device ? Yes


Logs

When starting the second song:

flutter: FS:---> openAudioSession 
flutter: FS:---> channelMethodCallHandler : openAudioSessionCompleted
flutter: FS:<--- channelMethodCallHandler : openAudioSessionCompleted
flutter: FS:<--- openAudioSession 
flutter: FS:---> setSubscriptionDuration 
flutter: FS:<---- setSubscriptionDuration 
flutter: FS:---> startPlayer 
flutter: FS:---> stop 
flutter: FS:<--- stop 
flutter: FS:---> _convert 
flutter: FS:---> needToConvert 
flutter: FS:<--- needToConvert 
flutter: FS:<--- _convert 
flutter: FS:---> channelMethodCallHandler : startPlayerCompleted
flutter: FS:<--- channelMethodCallHandler : startPlayerCompleted
flutter: FS:<--- startPlayer 
flutter: FS:---> openAudioSession 
flutter: FS:---> channelMethodCallHandler : openAudioSessionCompleted
flutter: FS:<--- channelMethodCallHandler : openAudioSessionCompleted
flutter: FS:<--- openAudioSession 
flutter: FS:---> setSubscriptionDuration 
flutter: FS:<---- setSubscriptionDuration 
flutter: FS:---> startPlayer 
flutter: FS:---> stop 
flutter: FS:<--- stop 
flutter: FS:---> _convert 
flutter: FS:---> needToConvert 
flutter: FS:<--- needToConvert 
flutter: FS:<--- _convert 
flutter: FS:---> channelMethodCallHandler : startPlayerCompleted
flutter: FS:<--- channelMethodCallHandler : startPlayerCompleted
flutter: FS:<--- startPlayer 
flutter: FS:---> pausePlayer 
flutter: FS:<--- pausePlayer 
flutter: FS:---> pausePlayer 
flutter: FS:<--- pausePlayer

Describe the bug

Using 2 SoundPlayers in the same application causes one of them to misbehave, when they are playing simultaneously. The first player starts to play the song of the second player and the durations of the song seems to not match anymore.

To Reproduce Steps to reproduce the behavior:

  1. Create an application with 2 SoundPlayers controlled by a button, each playing a different song.
  2. Start playing the first song.
  3. Before the first song is finished, start playing the second song.
  4. You should notice that the first player seems to start the second song with a bit of a delay, so both players are now playing the second song.

Expected behavior

I’m not sure, what the best behaviour is. Not all platforms support multiple sound outputs at the same time. I’d probably prefer to stop the first player implicitly in this case. Playing both songs at the same time is fine too.


Additional context**

flutter_sound already keeps track of the different audio sessions, so it should be somewhat easy to stop them automatically, although an event would need to be emitted, that the song is now paused. From my testing I don’t see any mixup there happening too, so the issues seem to be in TauEngine or lower at the OS level. This could also be handled at the application level, but since flutter_sound already keeps track of it, that sounds more appropriate. Tell me your thoughts and if it is not something, that can be done soon, I may look into how to implement that, but I’m not really well versed in flutter sound stuff yet. This may also actually be a feature request instead of a bug report, so feel free to reassign.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
Larpouxcommented, Dec 21, 2020

Hi @deepbluev7 . Thank you for your very detailed PR (Problem Report). Yes, Flutter Sound was supposed to be able to play several sound at the same time. This has not been tested very well, and I was thinking to create a new simple example doing that.

I am going to study your PR more carefully when I will have finished working on the fucking documentation (in a few days).

Thank you again. It would be really great if everybody fill PRs like your. Detailed, clear and positive.

1reaction
Larpouxcommented, Dec 31, 2020

Hi @deepbluev7 ,

I wrote a simple example doing three playbacks at the same time here.

I did not see any problems. Could you check on your side that everything OK ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Play multiple sounds using SoundPlayer - Stack Overflow
There is one simple way to play multiple sounds at once in C# or VB.Net. ... And provide such stream as a parameter...
Read more >
[check] Multiple SoundPlayers · Issue #546 - GitHub
Using 2 SoundPlayers in the same application causes one of them to misbehave, when they are playing simultaneously.
Read more >
Play multiple sound files at once - MSDN - Microsoft
I am curently "using System.Media;" and: SoundPlayer player0 = new SoundPlayer(@"C:\Users\noskn\Documents\Visual Studio ...
Read more >
Play multiple sounds with SoundPlayer and SDK DirectSound
This is my test application: * A Windows Form Application with two buttons * Background music button, (btnBackgroundTrack_Click)
Read more >
Playing Multiple Sounds in WPF Application | by IT. Delinquent
SoundPlayer : Can play audio files that are embedded resources in the application, however, this can only play one sound at once. MediaPlayer:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found