mciSendString,搜索类似命令“wait”的东西

时间:2016-07-09 00:06:05

标签: c++ winapi visual-c++ mcisendstring

我试图从一个列表中播放另一首mp3歌曲,问题是“等待”命令“冻结”所有节目,直到所有歌曲完成,我想要的是其他功能,如“暂停“或”停止“,在歌曲播放时仍能正常工作。我单独播放一首歌时没有任何麻烦。

我阅读了一些文档,看起来“status”命令是解决方案,但我不明白如何使用它。

以下是“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

1 个答案:

答案 0 :(得分:0)

也许你应该使用MM_MCINOTIFY标志和回调来避免冻结整个应用程序的阻塞调用?

请参阅CodeProject使用回调和标记的示例:http://www.codeproject.com/Articles/17279/Using-mciSendString-to-play-media-files