windows media player 播放視頻

1、新建windows應用程序項目,添加vedioForm窗體windows

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

3、代碼以下:this

 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     }  

[基本屬性]spa

URL:string 能夠指定媒體位置.net

enableContextMenu:Boolean 顯示/不顯示播放位置的右鍵菜單code

fullScreen:boolean 全屏顯示orm

stretchToFit:boolean 非全屏狀態時是否伸展到最佳大小視頻

uMode:string 播放器的模式,full:有下面的控制條; none:只有播放部份沒有控制條server

playState:integer 當前控件狀態,狀態變化時會觸發OnStatusChange事件blog

 

[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

相關文章
相關標籤/搜索