Here is my code:
#include <Windows.h>
#include <iostream>
#pragma comment(lib, "Winmm.lib")
int main() {
mciSendString("open \"*.mp3\" type mpegvideo alias mp3", NULL, 0, NULL);
mciSendString("play mp3", NULL, 0, NULL);
return 0;
}
When I do replace the "*.mp3" with the file path to my mp3 file and run my program, there is no audio that plays and the program end immediately, what am I doing wrong? There is no error it just ends without playing anything. Is there something I am missing or doing wrong? It might also be important to mention that I am using VC++.
mciSendString
doesn't actually cause your program to wait, so you would need to wait instead of ending the program. Alternatively, you can usePlaySound()
and specify theSND_SYNC
flag so that it waits for the file to finish playing.