Need .mp3 playlist using queue, playsound() does not work with this, any help would be appreciated

I need to make a simple queue playlist, using array. I've tried using playsound function, with winmm.lib & windows.h but there's no way to wait until the song is finished playing the current song and the play the next in playlist. I know it can be played synchronously but the I couldn't use next, prev, stop, etc functionality. Any help regarding this problem would be appreciated.

So, to sum up: I need a way to play the whole playlist with playsound() or an external library, with help for a beginner like me, that makes it possible to play the list.

Note: I know playsound only plays .wav files and I am using .wav files for now but it would be better if I could play .mp3 files using an external library or something.

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
  #include<iostream>
#include<conio.h>
#include<string>
#include <random>
#include<windows.h>
#pragma comment (lib, "winmm.lib")

using namespace std;

class playlist{
private:
	LPSTR Q[100];
	int s, r1, ra, f, r;
	char ch;
public:
	playlist(){
		for(int i=0; i<100; i++)
			Q[i] = "Empty";
		s =  r1 = 0;
		ra = 1;
		ch = '\0';
		f = r = -1;
	}
	void set_folder(){
		//input folder to scan for files from user and put them in queue
		Q[0] = "E:\\Mp3 files\\1.wav";		
		Q[1] = "E:\\Mp3 files\\2.wav";
		Q[2] = "E:\\Mp3 files\\3.wav";
		Q[3] = "E:\\Mp3 files\\4.wav";
		Q[4] = "E:\\Mp3 files\\5.wav";
		int temp = 0;
		for(int i=0; i<=100; i++)
			if(Q[i] != "Empty")
				temp++;
		r = temp;
	}
	void check(){		
		if(ra == 1)
			if(f == r)
				f = -1;
		if(r1 == 1)
			f--;
	}
	void play(){
		if(s == 1)
			while(s == 1)
				shuffle();
		else
			for(int i=f; i<=r; i++){
				PlaySound(TEXT(Q[f]), NULL, SND_ASYNC | SND_NODEFAULT );
				f++;
				check();
			}
	}
	void start(){
		f = 0;
		play();
	}
	void next(){
		//skip current song and play next in queue/playlist, if shuffle=1, call shuffle
		f++;
		play();
	}
	void prev(){
		//skip current song and play prev in queue/playlist, if shuffle=1, call shuffle
		f--;
		play();
	}
	void stop(){
		//stop playing the current song and reset the playlist
		PlaySound(NULL, 0, 0);
		f= -1;
	}
	void rep(){
		//stop playing and start playing again, call stop then start
		stop();
		start();
	}
	void view_op(){
		cout<<"Curently...\n\n\n";
		if(s==1)
			cout<<"\tShuffle is on!";
		else
			cout<<"\tShuffle is off!";
		if(r1==1){
			cout<<"\n\tRepeating current song!";
			ra = 0;
		}
		else if(ra==1){
			cout<<"\n\tRepeating all songs!";
			r1 = 0;
		}
	}
	void set_op(){
		cout<<"\n\n";
		cout<<"\n\tWhat would you like to do?\n";
		cout<<"\n\t1) Toggle Shuffle ON / OFF";
		cout<<"\n\t2) Toggle Repeat ONE / ALL";
		cout<<"\n\t3) Nothing\n\n\t";
		ch = getche();
		switch(ch){
		case '1':
			if(s==1)
				s = 0;
			else
				s = 1;
			break;
		case '2':
			if(r1==1){
				ra = 1;
				r1 = 0;
			}
			else{
				ra = 0;
				r1 = 1;
			}
			break;
		}
	}
	void opt(){
		system("color 06");
		do{
			system("cls");
			view_op();
			set_op();
			system("cls");
			view_op();
		}
		while(ch != '3');
	}
	void shuffle(){
		//play any random NON-EMPTY index of the queue
		//shuffle for an integer eqalent to the non-empty indexes in queue
		//f = index shuffled to
		//after played, shuffle again
		random_device dev;
		uniform_int_distribution<> random(0,r);
		f=random(dev);
		PlaySound(TEXT(Q[f]), NULL, SND_ASYNC | SND_NODEFAULT );
	}
	void display(){
		set_folder();
		system("cls");
		system("color 0D");
		cout<<"\n\tM         M          PPPPPPPPP         333333333";
		cout<<"\n\tM M     M M          P        P              33";
		cout<<"\n\tM  M   M  M          P        P            33";
		cout<<"\n\tM   M M   M          PPPPPPPPP          3333333          P L A Y E R";
		cout<<"\n\tM    M    M          P                         3";
		cout<<"\n\tM         M          P                         3";
		cout<<"\n\tM         M          P                 33333333";
		cout<<"\n\n\n\n\t\t1) >	Start Playlist";
		cout<<"\n\t\t2) >>	Skip/Next";
		cout<<"\n\t\t3) <<	Previous";
		cout<<"\n\t\t4) #	Stop";
		cout<<"\n\t\t5) <-'	Replay Platlist";
		cout<<"\n\t\t6) ...	Playlist options";
		cout<<"\n\t\t7) X	Exit\n\n\t";
		ch = getche();
		switch(ch){
		case '1':
			start();
			break;
		case '2':
			next();
			break;
		case '3':
			prev();
			break;
		case '4':
			stop();
			break;
		case '5':
			rep();
			break;
		case '6':
			opt();
			break;
		case '7':
			exit(1);
		default:
			cout<<"\n\n\tWrong input!!!";
			break;
		}
	}
	void loading(){
		system("color 0B");
		cout<<"\n\n\n\tLOADING: ";
		for (int i=0; i<55; i++){
			Sleep ( 50 );
			cout<<"|";
		}
	}
	void welcome(){
		PlaySound(TEXT("E:\\Mp3 files\\taa_daa.wav"), NULL, SND_ASYNC );
		cout<<"\n\n\n\n\n\t\twwwww            wwwww"<<endl;
		cout<<"\t\t www       w      www"<<endl;
		cout<<"\t\t  www     www    www"<<endl;
		cout<<"\t\t   www   wwwww  www"<<endl;
		cout<<"\t\t    wwwwwwwwwwwwww"<<endl;
		cout<<"\t\t     wwww    wwww e l c o m e ! ! !"<<endl;
		cout<<"\n\tPress any key to continue...";
		int a = 150;
		system ( "color 01" );
		Sleep ( a );		
		system ( "color 02" );
		Sleep ( a );		
		system ( "color 03" );
		Sleep ( a );		
		system ( "color 04" );
		Sleep ( a );		
		system ( "color 05" );
		Sleep ( a );		
		system ( "color 06" );
		Sleep ( a );		
		system ( "color 07" );
		Sleep ( a );		
		system ( "color 08" );
		Sleep ( a );		
		system ( "color 09" );
		Sleep ( a );		
		system( "color 0A" );
		Sleep( a );		
		system( "color 0B" );
		Sleep( a );		
		system( "color 0C" );
		Sleep( a );		
		system( "color 0D" );
		Sleep( a );		
		system( "color 0E" );
		Sleep( a );		
		system( "color 0F" );
		Sleep( a );
		system( "color 03" );
			getche();
	}
	void Mp3Player(){
		welcome();
		loading();
		do{
			display();
		}
		while(1);
	}
};

void main (){
	playlist p;
	p.Mp3Player();
}
The PlaySound() function can only play files for which there is an installed sound driver.

You might do better to use OpenAL.
Thanks for the reply, but, could you provide an example of the basic code for OpenAl. Additionally, i still have to play the whole playlist and I don't know how to wait until the file has been played and then play the next in playlist? If I use sleep(x) the program becomes unresponsive so I cant use next, prev, stop functions. Any help would be appreciated...
Topic archived. No new replies allowed.