سؤال

I want to play sound while the program is running in c++. I am using the code:

 void fighterplanesound() 
{PlaySound(TEXT("bombdrop.wav"), NULL, SND_FILENAME|SND_ASYNC);}

I thought the SND_ASYNC flag would fix this problem but it did not. What is happening is the program will pause or control will not move on until the sound is done playing. How can I play the sound while the program continues to run. To clarify, the program is a Windows console program that operates in an MS-DOS window.

هل كانت مفيدة؟

المحلول 2

Ok. What I figured out was that you can't include the PlaySound method in the function because even though the ASYNC flag was there, control had to fully execute the PlaySound method before returning, so don't put it in the function unless there is more code in the function(in which case the sound will play while that code is executing) or in other words, control will not return from the function until PlaySound is finished executing and because there is no other code in the function to execute, control waits until PlaySound method is finished and then moves on.

نصائح أخرى

How about playing the sound in a different thread?

Actually i had the same problem on my iOS app. You know the time that how long does it take to play your .wav file. You can create a Timer that calls your fighterplanesound() method each period of ending time of your file. Not the best solution but it works for me.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top