右击工具箱->选择项(I)... -> 显示"选择工具箱项" -> COM组件 -> Windows Media Player   wmp.dll 添加

[基本属性]  
URL:String; 指定媒体位置,本机或网络地址
uiMode:String; 播放器界面模式,可为Full, Mini, None, Invisible(不计大小写)
playState:integer; 播放状态。这个属性改变时同时引发PlayStateChange事件与StateChange事件。取值范围为枚举型:WMPLib.WMPPlayState,它的成员如下:
  wmppsUndefined = 0;   //未知状态
  wmppsStopped = 1;    //播放停止
  wmppsPaused = 2;     //播放暂停
  wmppsPlaying = 3;     //正在播放
  wmppsScanForward = 4;   //向前搜索
  wmppsScanReverse = 5;   //向后搜索
  wmppsBuffering = 6;     //正在缓冲
  wmppsWaiting = 7;      //正在等待流开始
  wmppsMediaEnded = 8;    //播放流已结束
  wmppsTransitioning = 9;    //准备新的媒体文件
  wmppsReady = 10;      //播放准备就绪
  wmppsReconnecting = 11;   //尝试重新连接流媒体数据
  wmppsLast = 12;       //上一次状态,状态没有改变
  在PlayStateChange中写代码可以防止播放rmvb等非默认类型的问题(用wmppsReady)。
  enableContextMenu:Boolean;    启用/禁用右键菜单
  fullScreen:boolean;         是否全屏显示   //播放器基本控制
  Ctlcontrols.play; 播放
  Ctlcontrols.pause; 暂停
  Ctlcontrols.stop; 停止
  Ctlcontrols.currentPosition:double; 当前进度
  Ctlcontrols.currentPositionString:string; 当前进度,字符串格式。如“00:23”
  Ctlcontrols.fastForward; 快进
  Ctlcontrols.fastReverse; 快退
  Ctlcontrols.next; 下一曲
  Ctlcontrols.previous; 上一曲   [settings] wmp.settings //播放器基本设置
  settings.volume:integer; 音量,0-100
  settings.autoStart:Boolean; 是否自动播放
  settings.mute:Boolean; 是否静音
  settings.playCount:integer; 播放次数
  //顺序播放
  wmp.settings.setMode("shuffle", False)
  //随机播放
  wmp.settings.setMode("shuffle", True)
  //循环播放
  wmp.settings.setMode("loop", True) [currentMedia] wmp.currentMedia //当前媒体属性
currentMedia.duration:double; 媒体总长度
currentMedia.durationString:string; 媒体总长度,字符串格式。如“03:24”
currentMedia.getItemInfo(const string); 获取当前媒体信息"Title"=媒体标题,"Author"=艺术家,"Copyright"=版权信息,"Description"=媒体内容描述, "Duration"=持续时间(秒),"FileSize"=文件大小,"FileType"=文件类型,"sourceURL"=原始地址
currentMedia.setItemInfo(const string); 通过属性名设置媒体信息
currentMedia.name:string; 同 currentMedia.getItemInfo("Title")

基本设置实例:

axWindowsMediaPlayer1.windowlessVideo = false;   //设为false后双击屏幕可以全屏
axWindowsMediaPlayer1.fullScreen = true; //设播放器全屏播放 axWindowsMediaPlayer1.URL = @"mms://192.168.0.102/vod/jingwei.wma";//播放资源 axWindowsMediaPlayer1.Ctlcontrols.play(); //播放
axWindowsMediaPlayer1.Ctlcontrols.stop(); //停止
axWindowsMediaPlayer1.Ctlcontrols.pause(); //暂停 axWindowsMediaPlayer1.settings.autoStart = true; //自动播放 axWindowsMediaPlayer1.settings.mute = false; //静音
axWindowsMediaPlayer1.settings.volume = 100; // 音量 int 0 ~ 100 100 是最大音量 axWindowsMediaPlayer1.currentMedia.duration.ToString();//影片长度
axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 30; //当前的播放位置 double axWindowsMediaPlayer1.currentMedia.getItemInfo("Title");//标题
axWindowsMediaPlayer1.currentMedia.getItemInfo("Author");//作者

全屏控制实例代码:

using System.IO;
using WMPLib; public videoPlay()
{
InitializeComponent(); //全屏设置及隐藏鼠标
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
//Cursor.Hide();
//播放器全屏
Rectangle screenSize = System.Windows.Forms.SystemInformation.VirtualScreen;//获取屏幕的宽和高
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Size = new System.Drawing.Size(screenSize.Width,screenSize.Height);
this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(0, 0);
this.axWindowsMediaPlayer1.Size = new System.Drawing.Size(screenSize.Width, screenSize.Height);
//播放器设置
axWindowsMediaPlayer1.uiMode = "None";//播放器样式
axWindowsMediaPlayer1.stretchToFit = true;//非全屏状态时是否伸展到最佳大小
axWindowsMediaPlayer1.enableContextMenu = false;//禁用播放器右键菜单 } private IWMPPlaylist videoList;//创建播放列表
private bool ifLoop = true;//视频是否循环 //设置是否循环播放
public bool IfLoop
{
get { return ifLoop; }
set { ifLoop = value; }
} //播放状态改变时发生
private void axWindowsMediaPlayer1_StatusChange(object sender, EventArgs e)
{
//判断视频是否已停止播放
if ((int)axWindowsMediaPlayer1.playState == 1)
{
//停顿2秒钟再重新播放
//System.Threading.Thread.Sleep(2000);
//重新播放
//axWindowsMediaPlayer1.Ctlcontrols.play();
}
}
//播放
public void videoStart()
{
axWindowsMediaPlayer1.Ctlcontrols.play();
}
//列表播放
public void videoListStart()
{
videoPlayList();//重新获取播放列表
axWindowsMediaPlayer1.Ctlcontrols.play();
}
//暂停
public void videoPause()
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
}
//重播
public void videoReplay()
{
videoStop();
videoStart();
}
//列表重播
public void videoListReplay()
{
axWindowsMediaPlayer1.currentPlaylist = videoList;//重新载入播放列表
videoStart();
}
//停止播放
public void videoStop()
{
//axWindowsMediaPlayer1.currentPlaylist.clear();//清除列表
axWindowsMediaPlayer1.Ctlcontrols.stop();
}
//视频静音
public void videoMute(bool t)
{
axWindowsMediaPlayer1.settings.mute = t;
}
//播放下一个视频
public void videoNext()
{
//判断当前所播放的视频是否是列表的最后一个
if (axWindowsMediaPlayer1.currentMedia.name == axWindowsMediaPlayer1.currentPlaylist.Item[axWindowsMediaPlayer1.currentPlaylist.count - 1].name)
{
}
else
{
axWindowsMediaPlayer1.Ctlcontrols.next();//播放下一个
}
}
//播放上一个媒体
public void videoPrevious()
{ //判断当前所播放的视频是否是列表的第一个
if (axWindowsMediaPlayer1.currentMedia.name == axWindowsMediaPlayer1.currentPlaylist.Item[0].name)
{
}
else
{
axWindowsMediaPlayer1.Ctlcontrols.previous();//播放上一个
}
} //获取播放类表及初始化
public void videoPlayList()
{
videoList = axWindowsMediaPlayer1.playlistCollection.newPlaylist("one");//创建播放列表
string path = @".\data\video";//媒体路径
DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileSystemInfo fsi in dir.GetFileSystemInfos())
{
if (fsi is FileInfo)
{
FileInfo fi = (FileInfo)fsi;
videoList.appendItem(axWindowsMediaPlayer1.newMedia(fi.FullName));
}
}
axWindowsMediaPlayer1.currentPlaylist = videoList;//查找到视频、播放类表
axWindowsMediaPlayer1.settings.setMode("loop", ifLoop);//设置类表循环播放
}

C#播放器控件的常用方法介绍的更多相关文章

  1. 使用VideoView自定义一个播放器控件

    介绍 最近要使用播放器做一个简单的视频播放功能,开始学习VideoView,在横竖屏切换的时候碰到了点麻烦,不过在查阅资料后总算是解决了.在写VideoView播放视频时候定义控制的代码全写在Actv ...

  2. C# Winform开发程序调用VLC播放器控件播放视频.

    VLC是个好东西,支持的格式多,还无广告,关键还有调用它的播放控件不用安装. 开个文章记录下调用这个控件的流水账,以便以后需要的时候查阅 创建工程 首先新建一个Winform工程. 这里姑且叫做VLC ...

  3. Delphi 媒体播放器控件

    樊伟胜

  4. 发现C#winform编程中不常用的控件(一)<FlowLayoutPanel控件><拆分器控件Splitcontainer >

    第一部分:FlowLayoutPanel控件 实现效果: 将FlowLayoutPanel做为导航菜单按钮的容器 以实现 某个菜单按钮不显示时 整体的导航菜单布局不至于"缺憾" 原 ...

  5. UWP 播放媒体控件

    最近我的uwp需要有一个有声朗读的功能,like this 点击声音按钮就可以有声朗读了.这里主要是用了媒体播放的控件. 一般我们把需求分为两种: 一种是不需要呈现播放器的样子,只需要用户点击一下别的 ...

  6. Winform中checklistbox控件的常用方法

    Winform中checklistbox控件的常用方法最近用到checklistbox控件,在使用其过程中,收集了其相关的代码段1.添加项checkedListBox1.Items.Add(" ...

  7. IOS的segmentedControl(分段器控件)的一些常用属性

    #pragma mark - 创建不同的分段器 //初始化方法:传入的数组可以是字符串也可以是UIImage对象的图片数组 UISegmentedControl *mysegmented = [[UI ...

  8. SWF加载器控件 SWFLoaderControl

    SWF加载器控件 书:165 <?xml version="1.0" encoding="utf-8"?> <s:Application xm ...

  9. NX二次开发-Block UI C++界面Face Collector(面收集器)控件的获取(持续补充 )

    Face Collector(面收集器)控件的获取 NX9+VS2012 #include <uf.h> #include <uf_obj.h> UF_initialize() ...

随机推荐

  1. java Properties的用法

    Properties是一个特殊的Map,因为和IO流牵扯到了一块…… import java.io.BufferedReader;import java.io.File;import java.io. ...

  2. SpringBoot之自定义验证码

    代码地址如下:http://www.demodashi.com/demo/14280.html 项目介绍 Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控 ...

  3. Matlab调用返回游标的存储过程的分析和处理

    2.Matlab调用Oracl带游标参数输出的存储过程 笔者也是将工作之中遇到的问题进行了搜集与整理,才完成该文的编写,希望能帮助到有需要的朋友. 2.1.PLSQL中的存储过程 PROCEDURE ...

  4. [ubuntu]为ubuntu设立“任务管理器”的组合键

    在windows下面,我们可以方便的使用ctrl+alt+delete调出任务管理器,那么在ubuntu下面如何实现呢?这里我们介绍两种方法:1.在终端下运行: 代码:gconf-editor 找到: ...

  5. 使用ShareSDK完成第三方(QQ、微信、微博)登录和分享

    这几天遇到一个需求:做第三方登录和分享.遇到了一些坑,把整个过程整理记录下来,方便他人,同时也捋一下思路. 当时考虑过把每个平台的SDK下载下来,一个一个弄,一番取舍后决定还是用ShareSDK.这里 ...

  6. if you are not making someone else's life better, then you are wasting your time.– Will Smith如果你不能给别人的生活带来改善,那么你就是在浪费你的宝贵时间。 --威尔 史密斯(程序员,你做的东西...)

    if you are not making someone else's life better, then you are wasting your time. – Will Smith 如果你不能 ...

  7. SSH2框架实现注冊发短信验证码实例

    这两天開始写程序了,让用SSH2框架,曾经没有接触过Java项目更没有接触过SSH2框架,所以用注冊開始了我Java之旅.后来发现,后台代码挺easy理解的,跟.net的差点儿相同.就是层与层之间的调 ...

  8. Python type() 函数

    描述 type() 函数如果你只有第一个参数则返回对象的类型,三个参数返回新的类型对象.类似isinstance() isinstance() 与 type() 区别: type() 不会认为子类是一 ...

  9. Python 列表 remove() 方法

    描述 Python 列表 remove() 方法通过指定元素的值来移除列表中某个元素的第一个匹配项,如果这个元素不在列表中会报一个异常. 语法 remove() 方法语法: L.remove(obj) ...

  10. Apache 隐藏 index.php,如将 tp5.com/index.php/hello/123 变成 tp5.com/hello/123

          以Apache为例,需要在index.php入口文件的同级添加.htaccess文件,内容如下: <IfModule mod_rewrite.c> Options +Follo ...