I am trying to play a wav file in the background of a game built in c++ with opengl. I am using the following line to play the wav file:
PlaySound("starwars.wav", NULL, SND_FILENAME|SND_LOOP);
The problem is when the music starts the animation stops. I tried starting the music at the press of a keyboard button, but when I do that the music starts and the all the animation stops. Is there a way to avoid this? I just want some music to play in the background and PlaySound seemed the simplest way to achieve that, given the fact it requires just a line of code.
You want to pass in
SND_ASYNC
This would make PlaySound return immediately, rather than waiting for the sound to finish playing, which in your case wouldn't as you are looping. IIRC PlaySound only allows one sound to play at any one time so it may be best to look for a sound library, especially if you are making a game.
In conclusion for your sample to work:
PlaySound("starwars.wav", NULL, SND_ASYNC|SND_FILENAME|SND_LOOP);
Please see this
If you are using the format playSound("*.wav",NULL,SND_SYNC|SND_LOOP) almost you are out of control of the animation of the game which will be frozen with the loop included in the playSound() function which is SND_LOOP but if you change the SND_SYNC with SND_ASYNC it would work exactly as you ordered but do not forget that this works for windows and do not forget to include the WINMM.LIB (window multimedia library) under the project/opengl/visual c++/link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With