mciSendString notify Question

Good day,
I´m doing a mp3 player, and i need the option of play all the songs of a playlist, but I don´t know how to do it. I have been reading, and it looks like " notify" flag is what I need, but I don´t understand how to use it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
case IDC_Play1: {
	if ((SendDlgItemMessage(hDlg, IDC_CHECK1, BM_GETSTATE, NULL, NULL)) == BST_CHECKED) {
            //Code for playing only one song, this works fine 
	}
	else {
	    char auxi[10] = "";
	    UINT index = SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0);
	    SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETTEXT, index, (LPARAM)auxi);
	    if (strcmp(auxi, "") == 0) {
		MessageBox(NULL, "No se selecciono cancion", "ERROR", MB_ICONERROR);
	    }
	    else {
		ShowWindow(GetDlgItem(hDlg, IDC_Play1), SW_HIDE);
		ShowWindow(GetDlgItem(hDlg, IDC_Pause1), SW_SHOW);
		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);


		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] = " notify";
		strcat_s(musica1, comillas);
		strcat_s(musica1, esperar);
		mciSendString(musica1, NULL, 0, hDlg);
		}//else
	}//else
}//case
break;

case MM_MCINOTIFY: {
	char comillas[MAX_PATH] = "\"";
	char comillas2[MAX_PATH] = "\"";
	strcat_s(comillas, szFileName);
	strcat_s(comillas, comillas2);
	char musica[MAX_PATH] = "stop ";
	strcat_s(musica, comillas);
	mciSendString(musica, NULL, 0, 0);
	char cerrar[MAX_PATH] = "close ";
	strcat_s(cerrar, comillas);
	mciSendString(cerrar, NULL, 0, 0);

	char song[10] = "";
	UINT cuenta = SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETCOUNT, NULL, NULL);
	UINT index = SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETCURSEL, NULL, NULL);
	index++;
	while (index < cuenta) {
		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);
		SendDlgItemMessage(hDlg, IDC_ListBox1, LB_GETTEXT, index, (LPARAM)song);
		char Cnum[10];
		aux = inicio;
		aux = aux->sig;
		do {
			_itoa_s(aux->folio, Cnum, 10);
			if (strcmp(song, 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(song, Cnum) == -1 || strcmp(song, Cnum) == 1);

		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] = " notify";
		strcat_s(musica1, comillas);
		strcat_s(musica1, esperar);
		mciSendString(musica1, NULL, 0, hDlg);
		}
	}
break;


The idea is that when the first song finish playing, go to te MM_MCINOTIFY, and then loop there until all the songs in the listbox finish playing.
Thanks.
Last edited on
The MM_MCINOTIFY message notifies an application that an MCI device has completed an operation


You need to check the wParam. If it has the value MCI_NOTIFY_SUCCESSFUL then the song is finished and you can start the next one.

Topic archived. No new replies allowed.