最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#播放背景音樂的方法小結(jié)

 更新時(shí)間:2015年04月24日 15:44:36   作者:米刀文  
這篇文章主要介紹了C#播放背景音樂的方法,實(shí)例總結(jié)了C#播放背景音樂的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例總結(jié)了C#播放背景音樂的方法。分享給大家供大家參考。具體分析如下:

最經(jīng)在寫winform程序,其中有用到播放背景音樂

特此收集了一些網(wǎng)上的教程:

1、調(diào)用非托管的dll

using System.Runtime.InteropServices;
//DllImport命名空間的引用
class test //提示音
{
 [DllImport("winmm.dll")]
 public static extern bool PlaySound(String Filename,int Mod,int Flags);
 public void Main()
 {
  PlaySound(@"d:/qm.wav",0,1);
 //把1替換成9,可連續(xù)播放
 }
}

2、播放系統(tǒng)自帶聲音

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();

3、使用System.Media.SoundPlayer播放wav

System.Media.SoundPlayer sp = new SoundPlayer();
sp.SoundLocation = @"D:\10sec.wav";
sp.PlayLooping();

4、使用MCI Command String多媒體設(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 ""E:\Music\青花瓷.mp3"" alias temp_alias",null,0,0); 
mciSendString("play temp_alias repeat", null, 0, 0); 
}

關(guān)于mciSendString的詳細(xì)參數(shù)說明,請參見MSDN,或是 http://blog.csdn.net/psongchao/archive/2007/01/19/1487788.aspx
5、使用axWindowsMediaPlayer的COM組件來播放
a.加載COM組件:ToolBox->Choose Items->COM Components->Windows Media Player:

b.把Windows Media Player控件拖放到Winform窗體中,把a(bǔ)xWindowsMediaPlayer1中URL屬性設(shè)置為MP3或是AVI的文件路徑,F(xiàn)5運(yùn)行。

如何使用Windows Media Player循環(huán)播放列表中的媒體文件?

假設(shè)我們有一個(gè)播放列表,下面的代碼可以實(shí)現(xiàn)自動(dòng)循環(huán)播放

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:\Music\SomeOne.avi";
 axWindowsMediaPlayer1.Ctlcontrols.play();
}

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論

瑞金市| 桂林市| 临清市| 黑水县| 韩城市| 格尔木市| 微博| 星子县| 高青县| 平和县| 濮阳县| 浦江县| 广德县| 武安市| 萨嘎县| 井研县| 兴国县| 竹北市| 乌鲁木齐市| 库车县| 长治县| 玉林市| 包头市| 什邡市| 桦南县| 银川市| 东平县| 突泉县| 乃东县| 虹口区| 冕宁县| 江源县| 宁远县| 松阳县| 措美县| 洞头县| 犍为县| 尚义县| 无棣县| 牟定县| 锡林郭勒盟|