3

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.

Toribio
  • 3,963
  • 3
  • 34
  • 48
Sam
  • 321
  • 5
  • 13
  • what have you done? show us some code. AND also tell us where your song1.wav resides. – Aniket Inge Oct 19 '12 at 19:06
  • 3
    Are you sure it can find the "song1.wav" file? Maybe the current working directory is not correct? To make sure, maybe you can try to specify a full path name in the PlaySound call. – Halim Qarroum Oct 19 '12 at 19:07

3 Answers3

4

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); 
Aniket Inge
  • 25,375
  • 5
  • 50
  • 78
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 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.

askmish
  • 6,464
  • 23
  • 42
  • Or use a full path instead of a relative path. – Remy Lebeau Oct 19 '12 at 20:49
  • OP's question suggests that he is using relative paths. So, answered according to that. Although, absolute paths are always good, but less flexible to changes in paths(a sceanrio, where a massive source code change will need to be done everytime the file path changes, which would be avoided by simply adding or removing a path in the PATH environment variable and using relative paths). – askmish Oct 19 '12 at 21:00
  • I suggest staying away from the `PATH` environment. Too many things already pollute it as it is. There is no reason not to use a full path in your code instead. If you are worried about the path changing, store the path in a variable that you assign at app startup and update if needed, then you can append relative filenames to that value when operating on files. – Remy Lebeau Oct 19 '12 at 21:31
  • @Remy: Agreed and That's what I would suggest, too. I intended to get the simplest working solution for OP, without altering the code at all. To make a point that there's probably no problem with OP's code and only specific to the referenced PATH. – askmish Oct 19 '12 at 22:04
0

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.