3

I am trying to use PlaySound and I put

#include <windows.h>
#include <mmsystem.h>
#pragma comment( lib, "Winmm.lib" )
using namespace std;

int main()
{

PlaySound(L"C:\\Users\\iD Student\\Downloads\\HarryPotter.mp3", 0, SND_FILENAME);

}

and instead of playing the sound I wanted it to, it played some default Windows sound.

Doctor Pickle
  • 63
  • 1
  • 8
  • 1
    Are you sure that's the way to play a sound? You don't actually [call the function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd743680%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396) in this code. – tadman Jul 27 '17 at 17:43
  • This is what I am putting at the top of my code. The actual code is a PlaySound line – Doctor Pickle Jul 27 '17 at 17:44
  • 1
    Please, post the *actual code* then by editing your question. – tadman Jul 27 '17 at 17:46
  • Sorry, I am very new to this – Doctor Pickle Jul 27 '17 at 17:48
  • It's okay to be new. Just take a little time to read over your question and make sure you've provided all the relevant information that can help someone else understand and/or reproduce your problem. – tadman Jul 27 '17 at 17:49
  • Got it. I'll make sure to do that. – Doctor Pickle Jul 27 '17 at 17:50
  • 2
    I might be wrong here, but I think `PlaySound` is limited to `.wav` type files, so you may need [another approach](https://stackoverflow.com/questions/22253074/how-to-play-or-open-mp3-or-wav-sound-file-in-c-program) for MP3 files. – tadman Jul 27 '17 at 17:52
  • 1
    Awesome! It worked. Thank you so much!! – Doctor Pickle Jul 27 '17 at 17:59
  • If you have a working line of code, it's probably worth adding that as a self-answer since it could help others. – tadman Jul 27 '17 at 17:59
  • Someone asked a similar question this week. PlaySound does not support mp3. – drescherjm Jul 27 '17 at 18:00

1 Answers1

1

PlaySound does not support .mp3 files. It only supports .wav files.

This is the simple code for playing sounds:

#include <windows.h>
#include <mmsystem.h>
#pragma comment( lib, "Winmm.lib" )
using namespace std;

int main()
{
//Replace C:\\Users\\iD Student\\Downloads\\HarryPotter.wav with the location of your file
PlaySound(L"C:\\Users\\iD Student\\Downloads\\HarryPotter.wav", 0, SND_FILENAME);

}
Doctor Pickle
  • 63
  • 1
  • 8