locked
PlaySound can't find my sound file RRS feed

  • Question

  • I'm trying to use PlaySound to play a simple beep sound for a basic game I am making in C++, however every time I run the code it plays the default windows "ding" sound which means it can't find my sound file. I have my file saved to the same directory where my cpp file is though so it should be able to find it right? I have even tried using the full path name when specifying and nothing works. I have all the necessary include files I believe and I have added "Winmm.lib" in the linker. What is happening.
    Monday, June 15, 2020 3:23 PM

All replies

  • If I test the default "tada" .wav on Windows 10, it works normally :

    PlaySound(TEXT("C:\\Windows\\Media\\tada.wav"), NULL, SND_FILENAME | SND_ASYNC);


    Monday, June 15, 2020 4:00 PM
  • I tested literally exactly what you have and it still gives the default windows sound. My brain is about to explode.
    Monday, June 15, 2020 4:10 PM
  • And if you test with another simple method like mciSendString :

    int rc = mciSendString(TEXT("open \"C:\\Windows\\Media\\tada.wav\" alias wav1 type mpegvideo"), NULL, 0, 0);
    if (rc == 0)
    {
    	rc = mciSendString(TEXT("play wav1"), NULL, 0, 0);
    }
    else
    {
    	TCHAR wsMessage[255] = TEXT("");
    	mciGetErrorString(rc, wsMessage, sizeof(wsMessage));
    	MessageBox(NULL, wsMessage, TEXT("Error"), MB_OK | MB_ICONSTOP);
    }

    • Edited by Castorix31 Monday, June 15, 2020 9:43 PM
    Monday, June 15, 2020 5:14 PM
  • Hi,

    Thanks for posting here.

    I also cannot reproduce this issue in my environment.You could do the following checks:

    1. Check if your .wav file is valid (try to test other .wav files).
    2. Check whether you use the correct character set, use PlaySoundA ("path\\file") or PlaySoundW(L"path\\file"), or as comment use PlaySound(TEXT("PATH\\file")).
    3. NOTE to use double backslashes in path.
    4. Check if there is a redirected folder in the path.

    If it still doesn't work, you could provide a minimal, reproducible sample with the .wav file.

    Best Regards,

    Drake


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 16, 2020 2:30 AM