C # play Sound

Source: Internet
Author: User



1. Play System Event Sound
System.Media.SystemSounds.Asterisk.Play ();
System.Media.SystemSounds.Beep.Play ();
System.Media.SystemSounds.Exclamation.Play ();
System.Media.SystemSounds.Hand.Play ();
System.Media.SystemSounds.Question.Play ();

2. Use System.Media.SoundPlayer to play. wav format sounds
     soundplayer Player = new SoundPlayer ();
            player. Soundlocation = Application.startuppath + "\ \" + "sounds/wallhit.wav";
            player. Load ();                   //synchronously loads the sound
            player. Play ();                    //enable new threads to play
           //player. Playlooping ();   //Loop playback mode
            Player. Playsync ();         //ui thread playback

3. Using Windows Media Player

Load COM components: Toolbox->choose items->com components->windows Media Player

Drag and drop the Windows Media Player control into the WinForm form and set the URL property in the AxWindowsMediaPlayer1 to MP3 or AVI's file path.


Program Interface for 4.MCI Command String Multimedia devices

Using System.Runtime.InteropServices;
public static UINT Snd_async = 0x0001;
public static UINT snd_filename = 0x00020000;
[DllImport ("Winmm.dll")]
public static extern uint mciSendString (string lpstrcommand,
String lpstrreturnstring, uint ureturnlength, uint hwndcallback);
public void Play ()
{
mciSendString (@ "Close Temp_alias", NULL, 0, 0);
mciSendString (@ "open" path. mp3 "" Alias Temp_alias ", NULL, 0, 0);
mciSendString ("Play Temp_alias repeat", NULL, 0, 0);
}

For more information on the program interface of the MCI Command String Multimedia device, refer to http://blog.csdn.net/psongchao/article/details/1487788

C # play Sound

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.