C#使用Windows Media Player播放音訊檔案
阿新 • • 發佈:2022-11-29
利用Windows Media Player播放音訊
C#程式中:用Windows Media Player播放聲音檔案和視訊檔案 a.工具箱->元件->(右鍵)選擇項->COM元件->Windows Media Playe 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(); }
出處:https://blog.csdn.net/liuyuehui110/article/details/54425396
=======================================================================================
C#使用Windows Media Player播放音訊檔案
使用的方法:
- 在toolbox上點右鍵,選擇“選擇專案(Choose Items)”,切到COM頁,找到 Windows Media Player, 勾選,確定
- 在toolbox上,把剛才加入的MediaPlayer控制元件,拖放到Winform上
程式碼:
axWindowsMediaPlayer1.URL = "檔案路徑,支援網路路徑";
axWindowsMediaPlayer1.Ctlcontrols.play();
出處:https://blog.csdn.net/S33638555/article/details/5324968
=======================================================================================
C#呼叫Media Player 控制元件播放音樂的常用方法及屬性
本文原創,轉載請註明出處!
【注意】
需先在專案屬性的引用的COM裡面新增名為Windows Media Player、路徑為C:\Windows\System32\wmp.dll引用! 引用後顯示為WMPLib,然後在程式最前面加上:
using WMPLib; //【示例】 WMPLib.WindowsMediaPlayer wmp = new WindowsMediaPlayer(); wmp.URL = @"G:\我的音樂\卓依婷 - 花好月圓.mp3"; wmp.controls.play();
windows media player 控制元件的常用屬性及方法
[基本屬性]URL; 指定媒體位置,本機或網路地址
uiMode:String; 播放器介面模式,可為Full, Mini, None, Invisible
playState:integer; 播放狀態,1=停止,2=暫停,3=播放,6=正在緩衝,9=正在連線,10=準備就緒
enableContextMenu:Boolean; 啟用/禁用右鍵選單
fullScreen:boolean; 是否全屏顯示 windowlessVideo:boolean; 是否顯示視訊影象 Ctlenable:boolean; 設定控制按鈕是否起作用,/* 我自己的開發環境中未找到這個屬性,我的環境:win10,vs2017 */
[controls] wmp.controls //播放器基本控制
controls.play; 播放
controls.pause; 暫停
controls.stop; 停止
controls.currentPosition:double; 當前進度
controls.currentPositionString:string; 當前進度,字串格式。如“00:23”
controls.fastForward; 快進
controls.fastReverse; 快退
controls.next; 下一曲
controls.previous; 上一曲 [settings] wmp.settings //播放器基本設定
settings.volume:integer; 音量,0-100
settings.autoStart:Boolean; 是否自動播放
settings.mute:Boolean; 是否靜音
settings.playCount:integer; 播放次數
[currentMedia] wmp.currentMedia //當前媒體屬性
currentMedia.duration:double; 媒體總長度
currentMedia.durationString:string; 媒體總長度,字串格式。如“03:24”
currentMedia.getItemInfo(const string); 獲取當前媒體資訊"Title"=媒體標題,"Author"=藝術家,"Copyright"=版權資訊,"Description"=媒體內容描述,"Duration"=持續時間(秒),"FileSize"=檔案大小,"FileType"=檔案型別,"sourceURL"=原始地址
currentMedia.setItemInfo(const string); 通過屬性名設定媒體資訊
currentMedia.name:string; 同 currentMedia.getItemInfo("Title")
[currentPlaylist] wmp.currentPlaylist //當前播放列表屬性
currentPlaylist.count:integer; 當前播放列表所包含媒體數
currentPlaylist.Item[integer]; 獲取或設定指定專案媒體資訊,其子屬性同wmp.currentMedia
出處:https://blog.csdn.net/liuxianan612/article/details/7016877
=======================================================================================
個人使用
=======================================================================================