How to play a sound file in c++. I am trying to make an alarm program. I've done everything but i need to play sound at certain time. please help..............

3 Years
Discussion Span
Last Post by Moschops

If using Windows:

`PlaySound("MyFile.wav", NULL, SND_FILENAME);`


`PlaySound("MyFile.wav", NULL, SND_FILENAME | SND_ASYNC);`

For linux you can play files by opening /dev/dsp and writing the file to it.

You could also use system and call aplay to play it.


Some Linux distributions don't use /dev/dsp, such as Red Hat distributions. I am trying to figure out the equivalent but no luck so far, at least pushing an mp3 to the ones I thought might work. The common audio interfaces for Linux are ALSA and PulseAudio. They are generally accessed via system API's and not direct output to a device file.


It may be easier to use one of the many common widget libraries; some of them have very simple interfaces for playing sound, and the library takes care of the heavy lifting involved in interfacing with your operating system.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.