PlaySound in C beeps but does not play wav file

随声附和 提交于 2019-11-29 16:06:57

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); 

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!