Hello,
I need to play sound in my c code. It could be wav, mp3 doesnt matter.. searched in web but didnt found simple solution.
Any suggestions?
Printable View
Hello,
I need to play sound in my c code. It could be wav, mp3 doesnt matter.. searched in web but didnt found simple solution.
Any suggestions?
Possibly printf("\a") but it's not guaranteed to work on all platforms.
Which os... which compiler...
On windows with a GUI capable compiler you can #include <windows.h> and #include <mmsystem.h> then use the PlaySound() api call (and yes, it works from console programs).
Working on Win XP, Microsoft Visual NET 2003 :>
Well.. A bit strange for me.
If after compiling i run program by pressing F5 from MS Visual SOUND WORKSCode:PlaySound(TEXT("swish.wav"), NULL, SND_FILENAME);
If i just open exe file from folder, or by using cmd (type: program.exe ).. i get just little "pyp" sound, but not the original wav.
That's because your program is closing before the sound completes... you can try adding SND_SYNC which should hold your program until the sound completes.... otherwise just put Sleep(5000); (for 5 seconds) right before the program exits.
Code:PlaySound("swish.wav",NULL,SND_FILENAME | SND_SYNC);
// optional
Sleep(1000);
return 0; }
khekhe:)
I figuret out.
It works fine now. The problem was that my exe file was in debug folder, and wav file in other destination. So i copied wav file to debug folder.
Thanks for help!