C# 视频播放器【DirectX】
来源:互联网 发布:ow各英雄伤害数据 编辑:程序博客网 时间:2024/04/19 09:23
事先准备:
1、DirectX 两个必备的dll文件http://download.csdn.net/detail/yao__shun__yu/5981799
2、下载解码器FinalCodecs1.13.0719.exe【找不到的加我群5307397】
代码块:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;using Microsoft.DirectX.AudioVideoPlayback;namespace ScreenServer{ public partial class VideoPlayer : Form { [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hPos, int x, int y, int cx, int cy, uint nflags); #region private Member //add by fuzhengwei 2013年8月21日 //临时存放视频播放路径 private static string videoUrlBuffer = null; //add by fuzhengwei 2013年8月21日 //记录播放时长 private static long duration; //add by fuzhengwei 2013年8月21日 //打开过滤 private readonly string filterText = "Video Files (*.avi; *.mov; *.mpg; *.mpeg; *.ts; *.wmv; *.vob; *.dat; *.rm; *.rmvb; *.flv)|*.avi; *.mov; *.mpg; *.mpeg; *.ts; *.wmv; *.vob; *.dat; *.rm; *.rmvb; *.flv"; //add by fuzhengwei 2013年8月21日 //Video private Video myVideo = null; #endregion public VideoPlayer() { InitializeComponent(); //窗口置顶 IntPtr HWND_TOPMOST = new IntPtr(-1); SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, 0x0001 | 0x0002); //窗口最大化 this.WindowState = System.Windows.Forms.FormWindowState.Maximized; } //add by fuzhengwei 2013年8月21日 //打开视频 private void openVideoToolStripMenuItem_Click(object sender, EventArgs e) { openVideoFileDialog.InitialDirectory = Application.StartupPath; openVideoFileDialog.Title = "Open Video File"; openVideoFileDialog.Filter = filterText; if(openVideoFileDialog.ShowDialog() == DialogResult.OK) { videoUrlBuffer = openVideoFileDialog.FileName; myVideo = new Video(videoUrlBuffer); myVideo.Owner = videoPanel; myVideo.Play(); duration = (int)myVideo.Duration; //调用显示时间函数 showTimeInPanel(duration); videoTimer.Enabled = true; } } //add by fuzhengwei 2013年8月21日 //播放视频 private void playVideoToolStripMenuItem_Click(object sender, EventArgs e) { if (null == videoUrlBuffer) { MessageBox.Show("请点击\"打开\"选择视频路径!"); } else { videoTimer.Enabled = true; showTimeInPanel(duration); myVideo.Play(); } } //add by fuzhengwei 2013年8月21日 //暂停视频 private void plauseToolStripMenuItem_Click(object sender, EventArgs e) { //暂停timer videoTimer.Enabled = false; myVideo.Pause(); } //add by fuzhengwei 2013年8月21日 //停止视频 private void stopToolStripMenuItem_Click(object sender, EventArgs e) { //暂停timer videoTimer.Enabled = false; //显示时间清零 showTimeInPanel(0); //显示时间清零 conShowTimeInPanel(0); myVideo.Stop(); } //add by fuzhengwei 2013年8月21日 //时间显示在屏幕上 private void showTimeInPanel(long durateTime) { videoTime.Text = ConvertTimeToString(durateTime); } //add by fuzhengwei 2013年8月21日 //每隔一毫秒显示一次时间在panel上 private void conShowTimeInPanel(long durateTime) { runTimelabel.Text = ConvertTimeToString(durateTime); } //add by fuzhengwei 2013年8月21日 //格式化时间 private string ConvertTimeToString(double time) { string timeFormat = "00:00:00"; int hours = 0; int minutes = 0; int seconds = 0; checked { hours = (int)time / 3600; minutes = ((int)time - (hours * 3600)) / 60; seconds = (int)time - hours * 3600 - minutes * 60; } timeFormat = string.Format("{0:D2}:{1:D2}:{2:D2}", hours, minutes, seconds); return timeFormat; } //add by fuzhengwei 2013年8月21日 //循环时间事件 private void videoTimer_Tick(object sender, EventArgs e) { conShowTimeInPanel((int)myVideo.CurrentPosition); } }}
上图:
- C# 视频播放器【DirectX】
- C#使用directx播放视频
- Visual C#使用DirectX实现视频播放
- Visual C#使用DirectX实现视频播放
- Visual C#使用DirectX实现视频播放
- C#如何使用DirectX实现视频播放
- Visual C#使用DirectX实现视频播放
- Visual C#使用DirectX实现视频播放
- C#中使用DirectX实现视频播放
- DirectX实现视频播放
- 基于DirectX和C#的一个简单视频播放器总结
- Visual C#使用DirectX实现视频播放1
- C#视频播放器
- C#视频播放器
- C#视频播放器
- C#视频播放器
- DirectX 在对话框播放视频
- directX视频播放------手动连接
- android 图片下载的一个库 还有个http请求列子
- Java学习笔记——访问权限控制
- hudson搭建经验总结(三)
- vim如何显示行号
- 题目1369:字符串的排列-九度
- C# 视频播放器【DirectX】
- Android 按钮的长按事件和抬起事件的监听
- Ubuntu 12.04 快捷键【持续更新中】
- 我喜欢听的一些好听的粤语歌,记录下来
- tomcat7源码分析
- 回文素数Prime Palindromes
- 一个比较好的opencv的博客
- 在Apache Tomcat 7设置redis作为session store
- 一个很好的在线工具网站