The two simplest ways to play sound in C language

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.