问题
In C, my PlaySound
is not throwing any errors... but instead of playing the file I want, it just beeps.
Any suggestions?
I tried :
PlaySound("song1.wav", NULL, SND_ALIAS | SND_APPLICATION);
And:
PlaySound("song1.wav", NULL, SND_FILENAME);
But I got the same result.
回答1:
Instead of using relative path like you have done:
PlaySound("song1.wav", NULL, SND_FILENAME);
Use an absolute path like:
PlaySound("F:\\path\\to\\your\\song\\song1.wav", NULL, SND_FILENAME);
回答2:
Quote from PlaySound API description, at msdn.microsoft.com:
PlaySound
searches the following directories for sound files: the current directory; the Windows directory; the Windows system directory; directories listed in thePATH
environment variable; and the list of directories mapped in a network.If the function cannot find the specified sound and the
SND_NODEFAULT
flag is not specified,PlaySound
uses the default system event sound instead(In your case the BEEP).If the function can find neither the system default entry nor the default sound, it makes no sound and returns
FALSE
.
So, add the file directory path into the PATH
environment variable in windows. That should fix your issue.
回答3:
I was in trouble with same situation like OP's and found solution for me. My solution is eliminating meta data of wav file.
Post (japanese)
Referring to post, PlaySound() API can't play some wav files that are exported with famous audio tool. (such as ProTools, CUBASE, StudioOne etc..)
And eliminating meta data makes it worked. in blog post, he opened some 'troubling' wave file with SoundEngine(japanese) and just 'save as' new file to eliminate wav RIFF meta information.
来源:https://stackoverflow.com/questions/12980801/playsound-in-c-beeps-but-does-not-play-wav-file