Pythonieer
Pythonieer

Reputation: 17

Using mciSendString to play an mp3 file and not working (and also not giving any error)

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++.

Upvotes: 0

Views: 653

Answers (1)

user13690398
user13690398

Reputation:

mciSendString doesn't actually cause your program to wait, so you would need to wait instead of ending the program. Alternatively, you can use PlaySound() and specify the SND_SYNC flag so that it waits for the file to finish playing.

Upvotes: 0

Related Questions