码迷,mamicode.com
首页 > Windows程序 > 详细

windows media player 播放视频

时间:2016-05-10 18:11:41      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:

一、新建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 播放视频

标签:

原文地址:http://www.cnblogs.com/haibing0107/p/5478653.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!