Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play a sound, wait for it to finish and then do something?

I'm writing a Windows Forms application which is supposed to play three sound files and at the end of each sound file, it's to change the source of an image.

I can get it to play the sounds using System.Media.SoundPlayer. However, it seems to play the sound in a different thread, continuing on.

The net effect of this is that only the last sound is played and all the images are changed.

I've tried Thread.Sleep, but it sleeps the whole GUI and after the sleep period everything happens at once and the last sound it played.

UPDATE

I thought PlaySynch was working, but it seems to freeze my GUI which is less than ideal. What else can I do?

like image 764
Omar Kooheji Avatar asked Sep 29 '08 13:09

Omar Kooheji


2 Answers

Did you try SoundPlayer.PlaySync Method? From the help:

The PlaySync method uses the current thread to play a .wav file, preventing the thread from handling other messages until the load is complete.

like image 145
Biri Avatar answered Nov 14 '22 21:11

Biri


Instead of using the Play method, use the PlaySync method.

like image 27
RodgerB Avatar answered Nov 14 '22 22:11

RodgerB