Reputation: 1
First question, sorry if I don't do something right :S. I'm attempting to loop a background audio track while a game created in the console window is played. This is part of a group project. The game runs fine but I simply can't get the audio track to play using the PlaySound() function. This is a test program I made to try to figure out the problem.
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
int main()
{
PlaySound(TEXT("D:\\CodeBlocks:\\Programming Work:\\SoundTest:\\castor.wav"), NULL, SND_FILENAME|SND_ASYNC|SND_LOOP);
if(PlaySound(TEXT("D:\\CodeBlocks:\\Programming Work:\\SoundTest:\\castor.wav"), NULL, SND_FILENAME|SND_ASYNC|SND_LOOP))
{
cout << "It's Working." << endl;
}
else
{
cout << "It's not working." << endl;
}
cout << "Hello world!" << endl;
return 0;
}
My test case returns true (or "It's working."), and when I tried it in the school computer lab, it would loop the default windows error tone, which plays when the function can't find the file you specified, even though I've given it the whole file path. I can't figure out why it can't find the file, I've quadruple checked that it is in fact located where I wrote the file path, and it still seems unable to find it. I've tried using both .mp3 and .wav formats for the audio file. Anyone know what's going on? (note: The linker needs to be given the winmm library for this)
Upvotes: 0
Views: 3888
Reputation: 1
Thanks guys, I found the actual problem, it wasn't even code all along. Turns out my audio file (castor.wav) was not actually in wav format, which is required by the PlaySound() function, even though the computer was telling me it was .wav (Even when I showed the properties of the file, it said it was in wav format).
This is because I attempted to convert it from a .mp3 by simply changing .mp3 to .wav, should have known better. After using an actual conversion program (and removing the exact file path and simply giving it TEXT("castor.wav") it works like a charm. Thanks for the help!
Upvotes: 0