Playing audio in WAV format in mmsystem

Source: Internet
Author: User
// Mmsystem play audio in WAV format
// Mmsystem supports *. wav sound format snd-> soundrecorder
UsesMmsystem; // reference mmsystem

// Play the system sound
{
. Default // This is a string ('str ').
Mailbeep
Systemexclamation
Systemexit
Systemhand
}
Playsound ('systemeg', 0, snd_async); // A pchar string

// Play the sound in the list box
Playsound (pchar (listbox1.items [listbox1.itemindex]), 0, snd_async );

// Play custom audio in WAV format
{
1. Place the WAV audio file in the program directory.
Playsound('hasta.wav ', 0, snd_async); // put the hasta.wav file in the program directory


2. Package the wav file to the *. Res file.

Implementation
{$ R *. DFM}
{$ R sound. Res} // reference the resource file *. Res, which must be created by yourself.
Playsound (pchar ('anuo '), 0, snd_asyncOrSnd_resource); // anuo is the identifier in *. Res.

}
// Stop playing
Playsound (0, 0 );

// Loop playback
Playsound ('systemeg', 0, snd_asyncOrSnd_loop); // A pchar string


// Package the WAV audio file into a program (WAV audio file)
Stp1. create an RC file; {sound file of the identifier sound format} {Chinese name supported}
Create a new notepad and input click wave "click.wav" to save this file as a *. RC file. Here I save it as sound. RC.
Note: The audio and audio files click.wav and sound. RC must be in the same directory.
Stp2. convert the RC file to the res file;
Copy the brcc32.exe file in the Delphi directory to the C: \ Windows directory and start running: Enter cmd to open the command bar and enter brcc32 c: \ Users \ Administrator \ Desktop \ sound. RC.
In this way, a sound. Res file is compiled.

Stp3.UsesMmsystem is introduced below;
InImplementationEnter {$ R sound. Res} below}

Stp4. use the following code to play music
Playsound ('click', 0, snd_asyncOr Snd_resource); // A pchar string


From Weizhi note (wiz)

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.