如下的內(nèi)容是關(guān)于C#播放背景音樂(lè)的幾種方法的內(nèi)容吐句,希望能對(duì)大伙有所幫助。
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.使用System.Media.SoundPlayer播放wav焊刹,mp3 System.Media.SoundPlayersp=newSoundPlayer(); sp.SoundLocation=@"戀愛(ài)ing.wav"; sp.PlayLooping();注:使用這種方法击罪,總是提示出該文件不是波形文件芋簿,很郁悶,還是沒(méi)有找出原因!骏全!使用VS2008的話(huà)苍柏,直接添加System.Media命名空間即可!很簡(jiǎn)單姜贡!3.使用MCICommandString多媒體設(shè)備程序接口播放mp3试吁,avi等
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 ""戀愛(ài)ing.mp3"" alias temp_alias", null, 0, 0);
mciSendString("play temp_alias repeat", null, 0, 0);
}
? private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
Thread thread = new Thread(new ThreadStart(PlayThread));
thread.Start();
}
}
private void PlayThread()
{
axWindowsMediaPlayer1.URL = @"E:MusicSomeOne.avi";
axWindowsMediaPlayer1.Ctlcontrols.play();
}
MCICommandString和WindowsMediaPlayer都有非常豐富的功能接口,這里不能一一介紹楼咳,可以參考MSDN中的具體描述.