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

13,906

Solution 1

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.

Solution 2

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

Share:
13,906

Related videos on Youtube

Omar Kooheji
Author by

Omar Kooheji

I've given up a life of code and turned to the dark side. I now lead a team of talented software engineers to deliver quality systems.

Updated on April 14, 2022

Comments

  • Omar Kooheji
    Omar Kooheji about 2 years

    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?

  • Omar Kooheji
    Omar Kooheji over 15 years
    Yeah I just found this, the only problem is that the Gui doesn't seem to be drawn... Will keep on working on it.