0

The program can compile and run, however, the music is not what I expect to be. Each time when I run the program, it only has a "ding" sound. When I comment the line PlaySound(TEXT("bgm.mp3"), NULL, SND_FILENAME); The "ding" sound does not come out. The file and the mp3 file are at the same path. What's wrong with my code? Many thanks.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
Pai
  • 327
  • 1
  • 3
  • 10
  • 1
    If `PlaySound` cannot find the specified file, it uses the default system event sound([see the documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/dd743680%28v=vs.85%29.aspx)). Also Whether the specified file will play or not also depends on the installed waveform-audio device driver. – Biruk Abebe May 02 '16 at 14:40
  • 1
    MP3 might not be supported by `PlaySound`. What if you use WAV file instead of MP3? – MikeCAT May 02 '16 at 14:41
  • The path is "\\UON2\Users05\3\psyjc3\MyProfile\Desktop\now\part1-v1\part1\part1\src\bgm.wav", I change mp3 to wav, but if I put it in the TEXT("\\UON2\Users05\3\psyjc3\MyProfile\Desktop\now\part1-v1\part1\part1\src\bgm.wav") there is still a "ding" sound. – Pai May 02 '16 at 14:42
  • Did you convert the file or did you just rename it? – molbdnilo May 02 '16 at 14:44
  • 1
    See if you need to be able to play MP3 files. Also, remember when using backslash in C++ strings that it can be used as part of an escape sequence, so you'll want something more like TEXT("\\\\UON2\\Users05\\3\\psyjc3\\MyProfile\\Desktop\\now\\part1-v1\\part1\\part1\\src\\bgm.‌​wav"). – Aenimated1 May 02 '16 at 14:45
  • If my file and the bgm.wav are in the same path, do I need to write the global path of my wav file? – Pai May 02 '16 at 14:53
  • PlaySound searches the current directory first, so if the file is located in the directory from which the application is launched, no, you won't need to specify the global path. However, sometimes it's not obvious which directory is the current one when using an IDE. – Aenimated1 May 02 '16 at 14:56
  • @Pai As pointed out, those single backslashes in your string are incorrect. Didn't the compiler give you a warning about "unknown escape sequences"? – PaulMcKenzie May 02 '16 at 14:57
  • Thanks all guys, I fixed this bug. :-) molbdnilo answers my question, I just rename it and the file did not convert to wav. :-( – Pai May 02 '16 at 14:57
  • *"What's wrong with my code?"* - You are using relative paths. This never ends well. – IInspectable May 02 '16 at 16:30

0 Answers0