Pergunta

i'm trying to make a program in which I can play music i.e mp3 files.I'm trying to do this by using the winmm library.At first when i tried linking it,the compiler gave errors from which i realized that the program hadn't been linked properly with the library but then i added the library file in the linker settings and now the program executes fine(no errors-suggesting that it has been linked properly) but no music is played.I can't figure out what the problem is.I'm currently using codeblocks,which uses gcc compiler.Can anyone explain what the problem is and why the music isn't playing? I'd be grateful if anyone can help me out! :)

my code(it simply prints the text but no music is played):

#include <stdio.h>
#pragma comment (lib, "winmm.a")
#include <windows.h>
#include <mmsystem.h>


int main()
{
    printf("Hello world!\n");

    mciSendString("play song.mp3",NULL,NULL,NULL);

    printf("\nY");

    mciSendString("pause song.mp3",NULL,NULL,NULL);
    mciSendString("close song.mp3",NULL,NULL,NULL);

    printf("\ndone");

   return 0;
}
Foi útil?

Solução

MCI commands return immediately. This means you immediately pause and close the mp3 hardly before playing started. Looking at the documentation you have to use the Wait Flag:

mciSendString("play song.mp3 wait",NULL,NULL,NULL);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top