Dan Silva
Dan Silva

Reputation: 1

mciSendString, searching something similar to command "wait"

I´m trying to play a mp3 song after another from a list, the problem is that "wait" command "freeze" all the program until all the songs finish, and what I want is the other functions, as "pause" or "stop", to still work while the song is playing. I don´t have any trouble when I play one song individually.

I read some documentation and it looks like "status" command is the solution, but I don´t understand how to use it.

Here is the code of "case IDC_Play:"

if ((SendDlgItemMessage(hDlg, IDC_CHECK1, BM_GETSTATE, NULL, NULL)) == BST_CHECKED) 
{//here goes the code for play only one song}

else {
    int cuenta = SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETCOUNT, NULL, NULL);
    int indice = 0;
    while (indice != cuenta) {
        char auxi[10] = "";
        UINT index = SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETCURSEL, 0);
        SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETTEXT, index, (LPARAM)auxi);
        if (strcmp(auxi, "") == 0) {
            MessageBox(NULL, "No se selecciono cancion", "ERROR", MB_ICONERROR);
        }
        else {
            char Cnum[10];
            aux = inicio;
            aux = aux->sig;
            do {
                _itoa_s(aux->folio, Cnum, 10);
                if (strcmp(auxi, Cnum) == 0) {
                    strcpy_s(szFileName, aux->mptres);
                    bmp1 = (HBITMAP)SendDlgItemMessage(hDlg, IDC_Imagen1, STM_GETIMAGE, IMAGE_BITMAP, 0);
                    bmp2 = (HBITMAP)LoadImage(NULL, aux->imagen, IMAGE_BITMAP, 140, 120, LR_LOADFROMFILE);
                    SendDlgItemMessage(hDlg, IDC_Imagen1, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp2);
                    }
                else {
                    aux = aux->sig;
                }
            } while (strcmp(auxi, Cnum) == -1 || strcmp(auxi, Cnum) == 1);

            ShowWindow(GetDlgItem(hDlg, IDC_Play1), SW_HIDE);
            ShowWindow(GetDlgItem(hDlg, IDC_Pause1), SW_SHOW);

            char comillas[MAX_PATH] = "\"";
            char comillas2[MAX_PATH] = "\"";
            strcat_s(comillas, szFileName);
            strcat_s(comillas, comillas2);
            char musica[MAX_PATH] = "open ";
            strcat_s(musica, comillas);
            strcat_s(musica, " type mpegvideo");
            mciSendString(musica, NULL, 0, 0);
            char musica1[MAX_PATH] = "play ";
            char esperar[MAX_PATH] = " wait";
            strcat_s(musica1, comillas);
            strcat_s(musica1, esperar);
            mciSendString(musica1, NULL, 0, 0);
            char parar[MAX_PATH] = "stop ";
            strcat_s(parar, comillas);
            mciSendString(parar, NULL, 0, 0);
            char cerrar[MAX_PATH] = "close ";
            strcat_s(cerrar, comillas);
            mciSendString(cerrar, NULL, 0, 0);

            index++;
            SendDlgItemMessage(hDlg, IDC_LIST1, LB_SETCURSEL, index, NULL);
            SendDlgItemMessage(hDlg, IDC_LIST2, LB_SETCURSEL, index, NULL);
            SendDlgItemMessage(hDlg, IDC_LIST3, LB_SETCURSEL, index, NULL);
            SendDlgItemMessage(hDlg, IDC_LIST4, LB_SETCURSEL, index, NULL);
            SendDlgItemMessage(hDlg, IDC_LIST5, LB_SETCURSEL, index, NULL);

            indice = index;
        } //else
    } //while
}//else

Upvotes: 0

Views: 187

Answers (1)

VladimirM
VladimirM

Reputation: 817

Maybe you should use MM_MCINOTIFY flag and callback to avoid the blocking call that freezes the whole application?

Please see an example of using the callback and flag there at CodeProject: http://www.codeproject.com/Articles/17279/Using-mciSendString-to-play-media-files

Upvotes: 0

Related Questions