PlaySound not looping when commanded.

Using this code in VC++ 2008 express
1
2
3
4
5
6
7
#include <windows.h>
#pragma comment(lib,"Winmm.lib")
using namespace std;
{
int main ( ) 
PlaySound(TEXT("c:\\ding.wav"), NULL, SND_LOOP);
}


I am unable to get the sound to loop.I've referenced MSDN on how it should work, but I can't seem to get this working. There is obviously something I'm over looking.

Also, I have tried SND_LOOP|SND_ASYNC and a few other combinations hoping it would have an effect.

I was wondering if anyone had a solution. (I removed most of the code because it doesn't seem to have an influence on the function when I commented it out. If you need to see the whole thing I'll post it.)
I am really stumped on this, I haven't made any progress.
Doesn't work for me either
Does this work?
PlaySound(TEXT("c:\\ding.wav"),NULL,SND_LOOP|SND_ASYNC);
I tried that also but no luck.
Try adding cin.get(); This worked for me:

1
2
3
4
5
6
7
8
9
10
#include <windows.h>
#pragma comment(lib,"Winmm.lib")
#include <iostream>
using namespace std;

int main ( ) 
{
PlaySound(TEXT("c:\\ding.wav"),NULL,SND_LOOP|SND_ASYNC);
cin.get();
}
You sir, are the man. It works great now, thank you. Do you mind explaining how console input fixed it.
Last edited on
It probably works because if you don't have a "pause" there, then the program ends before the sound even starts playing, since you aren't blocking and waiting for it to finish.
I see, and the reason you dont use system(PAUSE) is because an input is more simple and uses less resources?
Yes, and system() also opens a security hole in your program, so you will want to avoid using it if at all possible.
Ahhhh, awesome. Thank you for the tip.
Yeah I'm pretty sure it just needed a sort of pause so the program wouldn't end suddenly. It was a lucky guess lol.
Topic archived. No new replies allowed.