日期:2014-05-18 浏览次数:20415 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
namespace Video
{
public partial class Form1 : Form
{
private Microsoft.DirectX.AudioVideoPlayback.Video MyVideo = null;
public Form1()
{
InitializeComponent();
}
private void Open_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// 记录panel组件的大小
int height = panel1.Height;
int width = panel1.Width;
// 如果存在打开的Video文件,释放它
if (MyVideo != null)
{
MyVideo.Dispose();
}
// 打开一个新的Video文件
MyVideo = new Microsoft.DirectX.AudioVideoPlayback.Video(openFileDialog1.FileName);
// 把Video文件分配给创建的Panel组件
MyVideo.Owner = panel1;
// 以记录的panel组件的大小来重新定义
panel1.Width = width;
panel1.Height = height;
// 播放AVI文件的第一帧,主要是为了在panel中显示
MyVideo.Play();
MyVideo.Pause();
}
//确定窗体中的各按钮状态
if (MyVideo == null)
{
Play.Enabled = false;
Pause.Enabled = false;
Stop.Enabled = false;
}
else
{
Play.Enabled = true;
Pause.Enabled = true;
Stop.Enabled = true;
}
}
private void Play_Click(object sender, EventArgs e)
{
if (MyVideo != null)