c++visual-studiomp3mci

Why mciSendString cannot open my mp3 file?


I am trying to play MP3 audio in C++ Visual Studio 17.3.0, but keep getting MCIERROR 275 followed by 263.

My .mp3 file is in the same directory as my .cpp file.

My code goes something like this:

MCIERROR me = mciSendString(TEXT("open ""Music.mp3"" type mpegvideo alias mp3"), NULL, 0, NULL);
while(true){
    me = mciSendString(TEXT("play mp3"), NULL, 0, NULL);
}

Have tried different .mp3 files, different directory, and different function for playing the sound (PlaySound()), which gave me a very similar result/error.

What could be the cause of my problem?


Solution

  • The first is to open:

    mciSendString("open Summer.mp3 alias song",NULL,0,NULL)
    

    Add the relative path or absolute path of the file after open (depending on the relative position of the music you play and your program)

    We could understand alias as replacing your music name with the name after alias, which is convenient for us to carry out subsequent operations, only need to enter your alternative name (to save the trouble if the song name is long)

    The last three parameters can be written as I do, because we are just simply playing music, so there is no need to go into details.

    Next is to play:

    mciSendString("play song repeat",NULL,0,NULL);
    

    play+music name (or an alternative name after alias)+[play selection]

    Playback options include repeat, wait.

    repeat means to repeat the song.

    wait means that the function does not return until the song has finished playing.