PlaySound in C beeps but does not play wav file

2020-02-14 10:40发布

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.

3条回答
女痞
2楼-- · 2020-02-14 10:51

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); 
查看更多
别忘想泡老子
3楼-- · 2020-02-14 10:56

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 the PATH 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.

查看更多
够拽才男人
4楼-- · 2020-02-14 11:01

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.

查看更多
登录 后发表回答