命名空间 | 描述 |
microsoft.directx | 公共类和数学结构 |
microsoft.directx.direct3d | 3d图形和助手库 |
microsoft.directx.directdraw | direct draw 图形api。这是旧式命名空间,现在已经不需要使用它。 |
microsoft.directx.directplay | 用于多玩家游戏的网络api |
microsoft.directx.directsound | 声音支持 |
microsoft.directx.directinput | 输入设备支持(例如,鼠标和游戏杆) |
microsoft.directx.audiovideoplayback | 播放视频和音频(例如,在电脑上播放各自视频动画文件) |
microsoft.directx.diagnostics | 疑难解答 |
microsoft.directx.security | 访问安全性 |
microsoft.directx.security.permissions | 访问安全权限 |
属性 | 描述 |
audio | 获取视频文件中的音频对象,可用来后续的音频播放 |
caption | 获取或设置在form上播放视频的名称 |
currentposition | 获取或设置播放视频的当前位置 |
defaultsize | 获取播放视频的缺省的视频大小 |
fullscreen | 获取或设置视频文件是否在全屏模式下播放 |
iscursorhidden | 获取播放的视频时鼠标的状态:隐藏或显示 |
owner | 获取或设置视频播放的宿主组件 |
paused | 获取当前的播放状态是否处于暂停状态 |
playing | 获取当前的播放状态是否处于播放状态. |
seekingcaps | 获取是否可以搜索性能 |
size | retrieves and sets the size of the video for playback. |
state | 获取当前的播放状态 |
stopped | 获取当前的播放状态是否处于停止状态 |
stopposition | 获取播放的视频的停止播放位置 |
方法 | 描述 |
hidecursor | 隐藏当前播放视频的鼠标 |
open | 装入新的文件到video对象中 |
pause | 设置为暂停播放状态. |
play | 设置为播放状态 |
seekcurrentposition | 搜索转入到制定的播放位置 |
seekstopposition | 设置一个新的停止位置 |
showcursor | 显示当前播放视频的鼠标 |
stop | 设置为停止播放状态 |
video | 初始化一个新的video实例 |
图01:添加引用 |
using system ; using system.drawing ; using system.collections ; using system.componentmodel ; using system.windows.forms ; using system.data ; using microsoft.directx.audiovideoplayback ; //引入视频播放所要使用的direct x命名空间 |
private video myvideo = null ; //创建一个video实例 |
private void initializecomponent ( ) { this.panel1 = new system.windows.forms.panel ( ) ; this.button1 = new system.windows.forms.button ( ) ; this.button2 = new system.windows.forms.button ( ) ; this.button3 = new system.windows.forms.button ( ) ; this.button4 = new system.windows.forms.button ( ) ; this.openfiledialog1 = new system.windows.forms.openfiledialog ( ) ; this.suspendlayout ( ) ; this.panel1.dock = system.windows.forms.dockstyle.top ; this.panel1.location = new system.drawing.point ( 0, 0 ) ; this.panel1.name = "panel1" ; this.panel1.size = new system.drawing.size ( 540, 346 ) ; this.panel1.tabindex = 0 ; this.button1.location = new system.drawing.point ( 62, 380 ) ; this.button1.name = "button1" ; this.button1.size = new system.drawing.size ( 80, 38 ) ; this.button1.tabindex = 1 ; this.button1.text = "打开" ; this.button1.click += new system.eventhandler ( this.button1_click ) ; this.button2.location = new system.drawing.point ( 165, 380 ) ; this.button2.name = "button2" ; this.button2.size = new system.drawing.size ( 81, 38 ) ; this.button2.tabindex = 1 ; this.button2.text = "播放" ; this.button2.click += new system.eventhandler ( this.button2_click ) ; this.button3.location = new system.drawing.point ( 268, 380 ) ; this.button3.name = "button3" ; this.button3.size = new system.drawing.size ( 80, 38 ) ; this.button3.tabindex = 1 ; this.button3.text = "暂停" ; this.button3.click += new system.eventhandler ( this.button3_click ) ; this.button4.location = new system.drawing.point ( 371, 380 ) ; this.button4.name = "button4" ; this.button4.size = new system.drawing.size ( 81, 38 ) ; this.button4.tabindex = 1 ; this.button4.text = "停止" ; this.button4.click += new system.eventhandler ( this.button4_click ) ; this.openfiledialog1.defaultext = "avi" ; this.openfiledialog1.filter = "视频文件|*.avi||" ; this.openfiledialog1.title = "请选择播放的avi文件" ; this.autoscalebasesize = new system.drawing.size ( 6, 14 ) ; this.clientsize = new system.drawing.size ( 540, 461 ) ; this.controls.add ( this.button1 ) ; this.controls.add ( this.panel1 ) ; this.controls.add ( this.button2 ) ; this.controls.add ( this.button3 ) ; this.controls.add ( this.button4 ) ; this.formborderstyle = system.windows.forms.formborderstyle.fixeddialog ; this.maximizebox = false ; this.name = "form1" ; this.text = "visual c#中使用driectx实现媒体播放" ; this.load += new system.eventhandler ( this.form1_load ) ; this.resumelayout ( false ) ; } |
图03:【visual c#中使用driectx实现媒体播放】项目的界面设计 |
private void button1_click ( object sender, system.eventargs e ) { openfiledialog1.initialdirectory = application.startuppath ; if ( openfiledialog1.showdialog ( ) == dialogresult.ok ) { // 记录panel组件的大小 int height = panel1.height ; int width = panel1.width ; // 如果存在打开的video文件,释放它 if ( myvideo != null ) { myvideo.dispose ( ) ; } // 打开一个新的video文件 myvideo = new video ( openfiledialog1.filename ) ; // 把video文件分配给创建的panel组件 myvideo.owner = panel1 ; // 以记录的panel组件的大小来重新定义 panel1.width = width ; panel1.height = height ; // 播放avi文件的第一帧,主要是为了在panel中显示 myvideo.play ( ) ; myvideo.pause ( ) ; } //确定窗体中的各按钮状态 if ( myvideo == null ) { button2.enabled = false ; button3.enabled = false ; button4.enabled = false ; } else { button2.enabled = true ; button3.enabled = true ; button4.enabled = true ; } } |
private void button2_click ( object sender, system.eventargs e ) { if ( myvideo != null ) { myvideo.play ( ) ; } } |
private void button3_click ( object sender, system.eventargs e ) { if ( myvideo != null ) { myvideo.pause ( ) ; } } |
private void button4_click ( object sender, system.eventargs e ) { if ( myvideo != null ) { myvideo.stop ( ) ; } } |
//初始化窗体中各按钮的状态 private void form1_load ( object sender, system.eventargs e ) { if ( myvideo == null ) { button2.enabled = false ; button3.enabled = false ; button4.enabled = false ; } else { button2.enabled = true ; button3.enabled = true ; button4.enabled = true ; } } |
图04:【visual c#中使用driectx实现媒体播放】项目的运行界面 |