Click here to Skip to main content
15,891,787 members
Please Sign up or sign in to vote.
1.40/5 (3 votes)
See more:
how can we play audio files in c++? what should be the simple code to retrieve audio file and play it on the execution of the program?
Posted
Updated 24-Sep-19 11:53am

Use this API Function in windows.h:

C++
PlaySound("filename.wav", NULL, SND_ASYNC);


As I recall, you may have issues with files larger than 1mb. It's been a few years since I did unmanaged coding though, so this may no longer be an issue...

If you meant that you want to play MP3 files, google is your friend. If you add "codeproject" to your search phrase, you'll probably find a lot of article shere that describe how to play the desired sound file.
 
Share this answer
 
v2
Comments
Oshtri Deka 15-Mar-12 9:06am    
I agree. 5.
 
Share this answer
 
If you want only play .wav files then use

PlaySound("filename.wav", NULL, SND_ASYNC); but you need to add winmm.lib to your project

otherwise use DriectX Audio you have enough tutorial and source code in codeproject.com
 
Share this answer
 
C++
<pre lang="c++">
<pre>#include<windows.h>
#include<mmsystem.h>
#include<iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	
	 PlaySound("Alarm01.wav", NULL, SND_ASYNC);
	 system("pause");
	return 0;
}
 
Share this answer
 
v2
Comments
Kats2512 25-Sep-19 0:56am    
An unexplained code dump isn't going to help much, especially to a 7 year old post!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900