注册 登录
编程论坛 C# 论坛

C#视频播放器,非media Player插件

sndnnlfhvk 发布于 2010-11-05 10:16, 11212 次点击
看来论坛里面的非media player插件音乐播放器,我也写了个视频播放的。代码如下,用directX
程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Microsoft.DirectX;
using Microsoft.DirectX.AudioVideoPlayback;
namespace VideoPlayer
{
    public partial class MainForm : Form
    {
        private Video video = null;

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
           
        }

        private void btnView_Click(object sender, EventArgs e)
        {
         
                OpenFileDialog openDlg = new OpenFileDialog();
                openDlg.Filter="视频文件(*.wmv;*.avi)|*.wmv;*.avi;";

                if (openDlg.ShowDialog() == DialogResult.OK)
                {
                    if (this.video != null)
                    {
                        if (this.video.Playing)
                        {
                            this.video.Stop();

                          
                        }
                    }

                    this.lblFileName.Text = openDlg.FileName;
                    this.video = new Video(openDlg.FileName);
                    int width = this.panPlayOwner.Width;
                    int height = this.panPlayOwner.Height;
                  
                    this.video.Owner = this.panPlayOwner;
                    this.video.Owner.Width = width;
                    this.video.Owner.Height = height;
                    this.video.Play();

                  
                }
           
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            if (this.video != null)
            {
                if (this.video.Playing)
                {
                    this.video.Stop();
                }
                this.video.Play();
            }
        }

        private void btnPause_Click(object sender, EventArgs e)
        {
            if (this.video != null)
            {
                if (this.video.Playing)
                {
                    this.video.Pause();
                }
            }
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            if (this.video != null)
            {
                if (this.video.Playing)
                {
                    this.video.Stop();
                }
            }
        }

        //区域大小改变
        private void panPlayOwner_Resize(object sender, EventArgs e)
        {
            int width = this.panPlayOwner.Width;
            int height = this.panPlayOwner.Height;

            if (this.video != null)
            {
                this.video.Owner.Width = width;
                this.video.Owner.Height = height;
            }
        }

        private void btnFullScreen_Click(object sender, EventArgs e)
        {
            if (this.video != null)
            {
                this.video.Fullscreen = true;
            }
        }

        //退出全屏
        private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Escape)
            {
                if (this.video != null)
                {
                    if (this.video.Fullscreen == true)
                    {
                        this.video.Fullscreen = false;
                    }[local]1[/local]
                }

            }
        }

        private void panPlayOwner_DoubleClick(object sender, EventArgs e)
        {
            if (this.video != null)
            {
                if (this.video.Fullscreen)
                {
                    this.video.Fullscreen = false;
                }
            }
        }

  
    }
}


23 回复
#2
wangnannan2010-11-05 10:21
看看 不错 呵呵
#3
欲与天斗2010-11-05 12:44
呵呵
#4
c1_wangyf2010-11-05 14:10
好,学习了
#5
欲与天斗2010-11-06 09:23
很好啊,支持一下了
#6
五少2010-11-12 22:51
顶,顶,顶
#7
swordsaintwt2010-11-16 20:59
还是不完美啊,我下了看了下,有些wmv视频在播放时花屏,一段时间后电脑就蓝屏了,另外全屏以后就不知道怎么退回来了
#8
huqiang192010-11-19 13:19
对我这样的菜鸟来说太长了 看不大懂
#9
外传2010-11-19 15:56
  我又文盲了
#10
HBBoy2010-11-19 22:45
吼吼吼~~~支持一下下
#11
lovejojo2010-11-20 10:20
不错  学习一下
#12
huozhouyxj2011-05-01 16:32
那个播放模式的代码呢?我需要,谢谢
#13
erickwang2012011-05-05 11:20
顶一下。学习中
#14
hoolly2011-11-30 10:27
还行
#15
li4929860292012-03-11 14:18
正好用这个播放器,
#16
guocs2012-03-24 14:58
谢谢楼主分享!!!!!!!!
#17
Janyu2012-03-31 04:01
挺不错呢!
#18
wxwtcl2012-05-04 09:16
全屏用alt+f4能够退出,就是发现占用内存很大,不知道是什么缘故!
#19
konghui32012-08-03 16:34
支持,学习
#20
新加入的2013-05-18 21:00
嗯,很不错的帖子。但是小试了下,貌似不能播放.MKV等格式的视频吧。期待改进拓展
#21
wuyanlin2013-06-13 17:55
谢谢分享
#22
梨小橙2013-07-02 16:35
不错
#23
Always小凡2014-05-28 15:35
回复 楼主 sndnnlfhvk
下载学习参考一下
#24
kv552015-07-10 11:19
支持一下。
1