日期:2014-05-18  浏览次数:20388 次

请教个使用DirectX SDK开发视频播放功能的问题
这几天看了这么篇文章:使用DirectX实现视频播放,觉得挺有意思,于是自己也装了个SDK想试试。一样是WinForm程序,控件也是一模一样,代码目前我也没找到有什么区别,但是运行中会报错。.cs代码如下:
C# code
 
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)