winform播放視頻(windows media player)


1.找到windows media player

工具箱常規下邊右鍵,右鍵彈窗點擊“選擇項”,選擇工具箱窗口點擊“COM組件”,找到 Windows Media Player 勾選,點擊確定

2.使用windows media player

直接將windows media player控件拖動到窗體上,

3.屬性

(1)fullScreen:滿屏

(2)enableContextMenu:是否顯示右鍵菜單

(3)stretchToFit :非全屏狀態時是否伸展到最佳大小

(4)uMode: 播放器的模式,full:有下面的控制區(開始,暫停等); none:去掉控制區

(5)playState 當前控件狀態,狀態變化時會觸發OnStatusChange事件

{

  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.(重新連接)

}

(6)Ctlcontrols 可通過WindowsMediaPlayer.controls對播放器進行控制並取得相關的一些信息:

Ctlcontrols .play; 播放

Ctlcontrols .stop; 停止

Ctlcontrols .pause; 暫停

Ctlcontrols .next; 下一曲

Ctlcontrols .previous; 上一曲

Ctlcontrols .currentPosition:Double 當前播放進度

Ctlcontrols .currentPositionString:string 時間格式的字符串 “0:32″

(7)currentMedia 可以通過currentMedia取得當前媒體的信息

currentMedia.duration Double 總長度

currentMedia.durationString 時間格式的字符串 “4:34″

(8)currentPlaylist 可以通過currentPlaylist取得當前播放列表信息

(9)settings 可以通過WindowsMediaPlayer.settings對播放器進行設置,包括音量和聲道等。

settings.volume:integer 音量 (0-100)

settings.balance:integer 聲道,通過它應該可以進行立體聲、左聲道、右聲道的控制。
autoStart:自動播放

setMode("loop", true);  設置循環播放

4.簡單應用

(1)播放 

url可以為指向本地的,也可以為指向服務器的

player.URL = @"C:\Users\David\Desktop\test.mp4";

player.URL = @"https://apd-447d450320d04ab29affdaabb7c6c9f7.v.smtcdns.com/om.tc.qq.com/AadOWCPdxXO55VINjYS_LyKiKwp33RtYlXlajQRzj22o/uwMRJfz-r5jAYaQXGdGnC2_ppdhgmrDlPaRvaV7F2Ic/l0726gpni5u.mp4";

(2)列表

player.settings.autoStart = true; //設置自動播放
player.settings.setMode("loop", true); //設置循環播放

string url1 = @"http://test.campus.ximalaya.com/group1/M00/FF/32/wKgD3lxr0UOAcKI4AAgWfJ258MM781.mp4";
string url2 = @"https://apd-447d450320d04ab29affdaabb7c6c9f7.v.smtcdns.com/om.tc.qq.com/AadOWCPdxXO55VINjYS_LyKiKwp33RtYlXlajQRzj22o/uwMRJfz-r5jAYaQXGdGnC2_ppdhgmrDlPaRvaV7F2Ic/l0726gpni5u.mp4";
player.currentPlaylist.appendItem(player.newMedia(url1));
player.currentPlaylist.appendItem(player.newMedia(url2));

player.Ctlcontrols.play();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM