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