Use winmm. dll to control sound playback and winmm. dll sound playback

Source: Internet
Author: User

Use winmm. dll to control sound playback and winmm. dll sound playback

This section describes how to use winmm. dll to play a sound.

First, import two functions.

/// <Summary> /// send a control command to the media control interface /// </summary> /// <param name = "lpszCommand"> command, see /// http://msdn.microsoft.com/en-us/library/windows/desktop/dd743572 (V = vs.85 ). aspx </param> /// <param name = "lpszReturnString"> information returned by the command, if no information needs to be returned, it can be null </param> /// <param name = "cchReturn"> specify the string size of the returned information </param> /// <param name = "hwndCallback"> callback handle, if the notify ID is not specified in the command parameter, it can be new IntPtr (0) </param> // <returns> error code that returns the command execution status </returns> [DllImport ("winmm. dll ")] static extern Int32 mciSendString (string lpszCommand, StringBuilder returnString, int bufferSize, IntPtr hwndCallback ); /// <summary> /// return the description of the execution status error code /// </summary> /// <param name = "errorCode"> error returned by mciSendCommand or mciSendString code </param> /// <param name = "errorText"> description string of the Error Code </param> /// <param name = "errorTextSize"> specifies size </param> /// <returns> If the ERROR Code is unknown, returns false </returns> [DllImport ("winmm. dll ")] static extern bool mciGetErrorString (Int32 errorCode, StringBuilder errorText, Int32 errorTextSize );

Sample Code

Int error = mciSendString ("open C :\\ Users \ Angel \ Desktop \ 123.wav alias myDivece", null, 0, new IntPtr (0 )); if (error = 0) {mciSendString ("play myDivece", null, 0, new IntPtr (0); // play} else {StringBuilder errorText = new StringBuilder (); mciGetErrorString (error, errorText, 50); MessageBox. show (errorText. toString ());}


You can use the following statements to control playback:

MciSendString ("play myDivece", null, 0, new IntPtr (0); // play
MciSendString ("pause myDivece", null, 0, new IntPtr (0); // pause
MciSendString ("stop myDivece", null, 0, new IntPtr (0); // stop
MciSendString ("close myDivece", null, 0, new IntPtr (0); // close

 


C # How to control the sound size of a music?

C # code:
[DllImport ("winmm. dll ", SetLastError = true, CallingConvention = CallingConvention. winapi)] public static extern int waveOutSetVolume (int uDeviceID, int dwVolume); // Call waveOutSetVolume (0,100 );

The first parameter can be 0, indicating the preferred device.
The second parameter is volume: 0xFFFF is the maximum value, and 0x0000 is the minimum value. The high value (the first two digits) indicates the right audio volume, and the low value (the last two digits) indicates the left audio volume.
Int iVolume = 50; // volume (0-100)
Int left = Convert. ToInt32 (Convert. ToInt32 (iVolume ));
Int right = left;
Int volume = (left <8) | right;
WaveOutSetVolume (0, volume );

How to control the sound playing in flash? Do not copy from other places

Give you the simplest method.
The sound is put up, and the data stream in the attribute panel is not set to an event or something else.
Write the playback code on a button. The other one writes the stop code .!

Related Article

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.