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..............

If using Windows:

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

//or:

`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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.