-1

i have another dummy question for which i can't found good answer.

I have this program where i would like to play first sound, after which i would like to play second sound.

Basicly those sounds are supose to be different phrases like "this is sound number" "one" and son on and on.

I don't know why, but simple using various SoundPlayers results only with playing last sound- "one".

        SoundPlayer dzwiek = new SoundPlayer(@"E:\sokol\mp3\zdjecie_nr.wav");
        SoundPlayer dzwiek2 = new SoundPlayer(@"E:\sokol\mp3\1.wav");

        dzwiek.Play();
        dzwiek2.Play();

Would you kindly explain me why this is happening, and what should I do to prevent this issue problem in future?

2 Answers2

0

Check out this answer here..

How to know when SoundPlayer has finished playing a sound

Basically, use PlaySync. You'll most likely want to do this on a different thread.

If you want some ordering, it might be a good idea to just queue your sound events (to some limitation) and PlaySync on a background worker. Will have to consider you can run into some issues if a sound plays for a very long time and things get delayed.

Community
  • 1
  • 1
bgura
  • 860
  • 15
  • 33
0

I just looked at the documentation for the SoundPlayer class, which I've never used. The documentation makes clear that the Play method is asynchronous, but I couldn't find any indication that you could get a notification when it's done playing. This means that if you want to play two sounds synchronously, you'll have to use the PlaySync method, which has the unfortunate side-effect of freezing your GUI or requiring you to do the threading yourself.

adv12
  • 8,443
  • 2
  • 24
  • 48