Sound's through CMD

Hi i would like to ask if there is any way to play a sound from cmd.Not to execute the file with other programm through cmd..i would like to be something like Beep but a sound file
Yes. However, you'll need some other library to do so (or just do it the hard way and go directly through MIDI). On some operating systems, its easier than others. Here is an example for Windows (assuming a WAV file):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <windows.h>
#include <mmsystem.h>
#include <iostream>

int main() {
    // play a sound
    PlaySound(TEXT("filename.wav"), NULL, SND_ASYNC | SND_FILENAME | SND_LOOP);

    // do things here

    // program finish, wait for <ENTER> and then stop the sound and exit
    std::cin.sync();
    std::cin.get();
    PlaySound(NULL, NULL, 0);
    return 0;
}


You'll also need to link to winmm to do this.

EDIT:
For details, see http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx - also, this probably isn't a good BEEP substitute, if you want a BEEP substitute get rid of the SND_ASYNC and SND_LOOP flags.
Last edited on
Well i did that but on compile i get this error
undefined reference to `PlaySoundA@12'

dunno what to do..


EDIT:I found the problem.I just had to link the lib winmm..
I found that post http://www.cplusplus.com/forum/windows/44705/
and i managed to do it.Thanks
Last edited on
Topic archived. No new replies allowed.