C # play and pause a wav file

Source: Internet
Author: User

[DllImport ("winmm. DLL ",
EntryPoint = "PlaySound ",
SetLastError = true,
CharSet = CharSet. Unicode,
ThrowOnUnmappableChar = true)]
Private static extern bool PlaySound (string szSound, System. IntPtr hMod,
PlaySoundFlags flags );

[System. Flags]
Public enum PlaySoundFlags: int
{
SND_SYNC = 0x0000, // synchronous playback sound. The PlaySound function is returned after playback.
SND_ASYNC = 0x0001, // play the sound asynchronously. The PlaySound function returns immediately after playing the video.
SND_NODEFAULT = 0x0002, // do not play the default sound. If this flag is not displayed, PlaySound will play the default sound when no sound is found.
SND_LOOP = 0x0008, // replaying sound, must be used with the SND_ASYNC flag
SND_NOSTOP = 0x0010, // PlaySound does not interrupt the original sound broadcast and returns FALSE immediately
SND_NOWAIT = 0x00002000, // if the driver is busy, the function does not play the sound and returns immediately
SND_FILENAME = 0x00020000, // The pszSound parameter specifies the WAVE file name.
SND_RESOURCE = 0x00040004 // The pszSound parameter is the identifier of the WAVE resource. In this case, the hmod parameter is used.
}


Public void runSound ()
{

PlaySound (@ "E: \ alarm sound \ ALARM1.WAV", IntPtr. Zero,
SND_ASYNC | SND_FileNAME | SND_LOOP );
}

Private void button#click (object sender, EventArgs e)
{
PlaySound (null, IntPtr. Zero, SND_ASYNC );
}

Private void button2_Click (object sender, EventArgs e)
{
New Thread (new ThreadStart (runSound). Start ();
}

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.