c#.NET winform 利用windows media player播放視頻,循環播放視頻
開發環境:VS2005
原文:http://blog.csdn.net/slimboy123/archive/2010/06/23/5688616.aspx (轉載請說明出處)
在C#.NET windows應用程序做視頻播放,首先要用到com組件中windows media player,當然你也可以用其它的,這裏就以windows media player爲例。
一、新建windows應用程序項目,添加vedioForm窗體
二、在com組件中找到windows media player,添加引用
三、代碼如下:
四、OK 了,執行看效果。
以上代碼只是實現了單個視頻文件循環播放的效果,當然還可以播放一個視頻列表,這裏就不再贅敘。
以下是關於windows media player的控件詳細說明:
[基本屬性]
URL:string 可以指定媒體位置
enableContextMenu:Boolean 顯示/不顯示播放位置的右鍵菜單
fullScreen:boolean 全屏顯示
stretchToFit:boolean 非全屏狀態時是否伸展到最佳大小
uMode:string 播放器的模式,full:有下面的控制條; none:只有播放部份沒有控制條
playState:integer 當前控件狀態,狀態變化時會觸發OnStatusChange事件
[controls]
可通過WindowsMediaPlayer.controls對播放器進行控制並取得相關的一些信息:
controls.play; 播放
controls.stop; 停止
controls.pause; 暫停
controls.currentPosition:Double 當前播放進度
controls.currentPositionString:string 時間格式的字符串 “0:32″
[currentMedia]
可以通過WindowsMediaPlayer.currentMedia取得當前媒體的信息
currentMedia.duration Double 總長度
currentMedia.durationString 時間格式的字符串 “4:34″
[settings]
可以通過WindowsMediaPlayer.settings對播放器進行設置,包括音量和聲道等。
settings.volume:integer 音量 (0-100)
settings.balance:integer 聲道,通過它應該可以進行立體聲、左聲道、右聲道的控制。
Media Player Player.playState獲取播放狀態事件
Value State Description
0 Undefined Windows Media Player is in an undefined state.(未定義)
1 Stopped Playback of the current media item is stopped.(停止)
2 Paused Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location.(停留)
3 Playing The current media item is playing.(播放)
4 ScanForward The current media item is fast forwarding.
5 ScanReverse The current media item is fast rewinding.
6 Buffering The current media item is getting additional data from the server.(轉換)
7 Waiting Connection is established, but the server is not sending data. Waiting for session to begin.(暫停)
8 MediaEnded Media item has completed playback. (播放結束)
9 Transitioning Preparing new media item.
10 Ready Ready to begin playing.(準備就緒)
11 Reconnecting Reconnecting to stream.(重新連接)
原文:http://blog.csdn.net/slimboy123/archive/2010/06/23/5688616.aspx (轉載請說明出處)