How to play PlaySound() anything else than *.wav?

Hello, I have a problem, I want to play some long sound files for a playlist made in C++ and the .wav files makes the file so big. Can you help me to play in another format, somehow?

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
#include <iostream>
	#include <windows.h>
	#include <string>
	#include "resource.h"
	#include <conio.h>
	#pragma comment (lib, "winmm.lib")

	using namespace std;
	int main()
	{
		int choice;
		string choicee = "Your choice: ";
		string newchoice = "Your new choice: ";

		cout << "Welcome to UrsAWARLOrd's Playlist Audio Player" << endl;
			Sleep(750);
			cout << "Choose a song to listen from below by writing its number. To exit the program insert \"0\"" << endl << endl;
			Sleep(750);
			cout << "Song ID  Artist name \t \t Song name \t Release date"<< endl;
			cout << "1. \t Two Steps From Hell \t Archangel \t Released: 2011" << endl;
			cout << "2. \t Audiomachine \t \t Ashes of Time \t Released: 2015" << endl;
			cout << choicee; cin >> choice; cout << endl;
			if (choice == 2)
			{
				goto choice2;
			choice2:
				PlaySound(MAKEINTRESOURCE(IDR_WAVE1), NULL, SND_RESOURCE | SND_ASYNC); 
				cout << newchoice; cin >> choice;
				cout << endl;
				if (choice == 0)
					return 0;
				if (choice == 1)
					goto choice1;
				if (choice == 2)
					goto choice2;
			}
			if (choice == 1)
			{
				goto choice1;
				choice1:
				PlaySound(MAKEINTRESOURCE(IDR_WAVE2), NULL, SND_RESOURCE | SND_ASYNC);
				cout << newchoice; cin >> choice;
				cout << endl;
				if (choice == 0)
					return 0;
				if (choice == 2)
					goto choice2;
				if (choice == 1)
					goto choice1;
			}
			if (choice == 0)
			return 0;

	}
Last edited on
PlaySound will only play .wav files. To play files of any other format, you will have to write a decoder and play those files. The easiest solution would be to use a library for this purpose, but if you want to do it yourself, I suggest taking a look at the waveOut family of functions. These functions play raw music data. You will have to write a decoder to convert the file format you wish to play to raw music data, how to implement the decoder depends on the file format you wish to play.
Topic archived. No new replies allowed.