1, assume that only need to play the waveform file WAV format sound, very easy. Just a word:
PlaySound (TEXT ("Data\\1.wav"), NULL, Snd_filename | Snd_async | Snd_loop);
Here just provide methods, specific questions to explore on their own.
Full C language code:
#include <windows.h> #pragma comment (lib, "Winmm.lib") int main (int argc, char *argv[]) {//file type can only be waveform file PlaySound ( TEXT ("Data\\1.wav"), NULL, Snd_filename | Snd_async | Snd_loop); Sleep (50000);//wait for the sound to play return 0;}
2, False imagine playing mp3 format sound, very troublesome, but there is a way very easy. It just needs a word:
mciSendString ("Play Data\\1.wav", null,0,null);
Full C language code:
#include <windows.h> #pragma comment (lib, "Winmm.lib") For MCI (medium control Interface, media controls interface) int main (int argc, char *argv[]) { //file type can be: MP3, WAV, AVI, etc. mcisendstring ("Play Data\\1.wav", //mci command string NULL, //buffer to hold feedback information 0, //buffer length null); //handle to callback form, typically null sleep (50000); //waiting for sound to play return 0;}
the same specific things to search by themselves.
The two simplest ways to play sound in C language