Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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 13-Mar-12 1:19am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use this API Function in windows.h:
 
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.
  Permalink  
v2
Comments
Oshtri Deka at 15-Mar-12 9:06am
   
I agree. 5.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 20 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100