windows media player 播放視頻

來源:互聯網
上載者:User

標籤:

一、建立windows應用程式項目,添加vedioForm表單

二、在com組件中找到windows media player,添加引用

三、代碼如下:

 1 public partial class VedioForm : Form   2 {   3         private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1;   4         public VedioForm()   5         {   6             InitializeComponent();   7             InitVedio();   8         }   9         private void VedioForm_Load(object sender, EventArgs e)  10         {   11             InitVedioUrl();  12             InitEvent();  13         }  14     //初始化播放控制項  15         private void InitVedio()  16         {  17             this.axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer();  18             this.axWindowsMediaPlayer1.Enabled = true;  19             this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(0, 400);  20             this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";  21             this.axWindowsMediaPlayer1.Size = new System.Drawing.Size(800, 500);  22             this.axWindowsMediaPlayer1.TabIndex = 2;  23             this.Controls.Add(this.axWindowsMediaPlayer1);  24         }  25         //初始化播放控制項的視頻檔案地址  26         protected void InitVedioUrl()  27         {  28             this.axWindowsMediaPlayer1.URL = @"D:/Vedio/default.wmv";  29         }  30           31           32         protected void InitEvent()  33         {  34             axWindowsMediaPlayer1.StatusChange += new EventHandler(axWindowsMediaPlayer1_StatusChange);  35         }  36           37         //通過控制項的狀態改變,來實現視頻迴圈播放  38         protected void axWindowsMediaPlayer1_StatusChange(object sender, EventArgs e)  39         {  40             /*  0 Undefined Windows Media Player is in an undefined state.(未定義) 41                 1 Stopped Playback of the current media item is stopped.(停止) 42                 2 Paused Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location.(停留) 43                 3 Playing The current media item is playing.(播放) 44                 4 ScanForward The current media item is fast forwarding. 45                 5 ScanReverse The current media item is fast rewinding. 46                 6 Buffering The current media item is getting additional data from the server.(轉換) 47                 7 Waiting Connection is established, but the server is not sending data. Waiting for session to begin.(暫停) 48                 8 MediaEnded Media item has completed playback. (播放結束) 49                 9 Transitioning Preparing new media item. 50                 10 Ready Ready to begin playing.(準備就緒) 51                 11 Reconnecting Reconnecting to stream.(重新串連) 52             */  53         //判斷視頻是否已停止播放  54             if ((int)axWindowsMediaPlayer1.playState == 1)  55             {  56                 //停頓2秒鐘再重新播放  57                 System.Threading.Thread.Sleep(2000);  58         //重新播放  59                 axWindowsMediaPlayer1.Ctlcontrols.play();  60             }  61         }  62     }  

[基本屬性]

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

windows media player 播放視頻

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.