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();

 

posted @ 2019-03-06 16:13  翻白眼的哈士奇  阅读(7466)  评论(0编辑  收藏  举报