I am trying to use the playsound function i have the code

PlaySound(L"C:\Documents and Settings\Louisa\My Documents\Visual Studio 2010\Projects\Ninja_Wars\Ninja_Wars\music.wav",NULL,SND_FILENAME|SND_ASYNC | SND_LOOP);

  Sint32 delta;

But when i play the game all i hear is a beeping sound- the one windows has when there is an error or something. Can anyone help me as to why this is happening?

Dani AI

Generated

As posted, the audible "beep" usually means the audio API failed to open or play the file. and pointed at path/filename issues and default-beep behavior, and raised the linker angle. The next useful steps are concrete checks and a couple of fixes you can apply right away.

First, make sure the multimedia library is actually linked into the build. In Visual Studio: Project -> Properties -> Linker -> Input -> Additional Dependencies, add the multimedia library, or add a single-line pragma to your source so the linker gets it automatically:

#pragma comment(lib, "winmm.lib")

Second, verify the file the program is trying to open is the file you expect at runtime. The debugger working directory isn't necessarily the project folder; confirm the full runtime path. Useful checks: log the full path just before the play call, test existence with a filesystem check (or GetFileAttributes), and inspect the return value of the play call (it returns zero on failure). Also watch for OS differences — the literal "Documents and Settings" layout changed after XP — and prefer constructing paths with a known-folder API or placing the WAV in your executable output folder while debugging.

Third, confirm the WAV itself is playable by Windows (try double-clicking in Explorer). Some WAV variants need codecs; if Explorer can’t play it, PlaySound won’t either. If you need support for compressed formats or long-running streamed audio, consider higher-level APIs (mciSendString, Media Foundation, or a cross-platform audio library).

For definitive behavior and flags, see the Microsoft documentation for the PlaySound function: . These steps should help pinpoint whether the issue is linking, path/working-directory, file accessibility, or an unsupported audio format.

Recommended Answers

All 3 Replies

Hi new2programming :-)

Replace \ with \\ in the string.

\ is used to put special characters in a string ('\n' is a newline). To put a '\' in a string you type '\\'.

The beeping sound might be caused by the fact that the file can't be found.

1. Replace '\' with '\\'
2. Use parameter SND_NODEFAULT to suppress the beep when no file is found.
3. PlaySound can only play .wav files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.