Hi,
I want to add sound to my program, but everything "freezes" until the sound is over. It prints '1', then plays sound, and when the sound ends, it prints '2'. I want print '1', play sound, and when sound is playing, print '2'.
for(int i = 1; i < 100; i++)
{
Sleep(250); //250ms, so that the numbers don't count up too fast
if(i == 10) //on the 10th iteration of the loop start playing the sound
{
PlaySound("C:/WINDOWS/Media/notify.wav", NULL, SND_ASYNC);
}
//you should still get numbers to print while the sound is playing
cout << endl << i;
}
The SND_ASYNC flag works, but your program is so short that the process terminates before the sound has a chance to play.
booradley60 is correct. With the SND_ASYNC flag, the function returns immediately after starting the sound. Your main method returns before you have a chance to actually hear the sound.