zoukankan      html  css  js  c++  java
  • C#利用微软DirectX做的视频播放器

    C#利用微软DirectX做的视频播放器
    2008-12-07 11:11
    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 playVideoProject
    {
        public partial class Form1 : Form
        {
            private Video myvideo = null;
            public Form1()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                openFile.InitialDirectory=Application.StartupPath;//获取对话框显示时的初始目录
                if (openFile.ShowDialog() == DialogResult.OK)
                {
                    // 记录panel组件的大小
                    int height = panel1.Height;
                    int width = panel1.Width;
                    // 如果存在打开的Video文件,释放它
                    if (myvideo != null)
                    {
                        myvideo.Dispose();
                    }
                    // 打开一个新的Video文件
                    myvideo = new Video(openFile.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 button3_Click(object sender, EventArgs e)
            {
                if (myvideo != null)
                {
                    myvideo.Pause();
                }
            }
            private void button2_Click(object sender, EventArgs e)
            {
                if (myvideo != null)
                {
                    myvideo.Play();
                }
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                if (myvideo == null)
                {
                    button2.Enabled = false;
                    button3.Enabled = false;
                    button4.Enabled = false;
                }
                else
                {
                    button2.Enabled = true;
                    button3.Enabled = true;
                    button4.Enabled = true;
                }
            }
            private void button4_Click(object sender, EventArgs e)
            {
                if (myvideo != null)
                {
                    myvideo.Stop();
                }
            }
            private void panel1_Paint(object sender, PaintEventArgs e)
            {
            }
        }
    }

  • 相关阅读:
    阿里云POLARDB荣膺2019中国数据库年度最佳创新产品
    实时大数据开发难、运维难、应用难?来,一站解决!
    阿里云应用实时监控 ARMS 再升级,支持 Prometheus 开源生态
    一线实践 | 借助混沌工程工具 ChaosBlade 构建高可用的分布式系统
    使用DataX同步MaxCompute数据到TableStore(原OTS)优化指南
    Twitter 宣布抛弃 Mesos,全面转向Kubernetes
    阿里云Kubernetes服务上使用Tekton完成应用发布初体验
    Knative Tracing 介绍
    不断被取代的传统职业:快速发展的智能交互
    bzoj1433: [ZJOI2009]假期的宿舍
  • 原文地址:https://www.cnblogs.com/xianyin05/p/1449863.html
Copyright © 2011-2022 走看看