国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#播放背景音樂的方法小結

2020-01-24 01:55:49
字體:
來源:轉載
供稿:網友

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

最經在寫winform程序,其中有用到播放背景音樂

特此收集了一些網上的教程:

1、調用非托管的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,可連續播放 }}

2、播放系統自帶聲音

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多媒體設備程序接口播放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); }

關于mciSendString的詳細參數說明,請參見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窗體中,把axWindowsMediaPlayer1中URL屬性設置為MP3或是AVI的文件路徑,F5運行。

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

假設我們有一個播放列表,下面的代碼可以實現自動循環播放

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#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 工布江达县| 天镇县| 中牟县| 忻州市| 舞钢市| 辽阳市| 玛沁县| 怀宁县| 隆安县| 佛学| 卢龙县| 厦门市| 沛县| 凌源市| 麦盖提县| 凤山市| 临泽县| 灵川县| 隆化县| 达日县| 通化市| 邓州市| 综艺| 綦江县| 曲周县| 突泉县| 新龙县| 远安县| 乐东| 原平市| 英吉沙县| 甘孜| 八宿县| 聂荣县| 广安市| 卫辉市| 宣汉县| 安塞县| 蛟河市| 河南省| 呼图壁县|