标题:用QuartzTypeLib.dll做过视频的朋友请进来帮忙看一下,winform程序。
只看楼主
流氓13少
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-3-13
 问题点数:0 回复次数:3 
用QuartzTypeLib.dll做过视频的朋友请进来帮忙看一下,winform程序。
  用QuartzTypeLib.dll做视频如何获取该视频的时长呢,还有我用ProgressBar做视频的进度条,如何使他与视频同步,当视频缓冲时,他就停止。
我是新手。
搜索更多相关主题的帖子: 视频 朋友 如何 
2012-03-13 22:19
流氓13少
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-3-13
得分:0 
程序代码:
 public partial class mediaplayer : Form
    {
        private  components;
        private const int WM_APP = 0x8000;
        private const int WM_GRAPHNOTIFY = WM_APP + 1;
        private const int EC_COMPLETE = 0x01;
        private const int WS_CHILD = 0x40000000;
        private const int WS_CLIPCHILDREN = 0x2000000;

        private FilgraphManager m_objFilterGraph = null;
        private IBasicAudio m_objBasicAudio = null;
        private IVideoWindow m_objVideoWindow = null;
        private IMediaEvent m_objMediaEvent = null;
        private IMediaEventEx m_objMediaEventEx = null;
        private IMediaPosition m_objMediaPosition = null;
        private IMediaControl m_objMediaControl = null;
        enum MediaStatus { None, Stopped, Paused, Running };
        private MediaStatus m_CurrentStatus = MediaStatus.None;
        OpenFileDialog openFileDialog;

        private int second = 0;
        private int minute = 0;
        //private int hour = 0;
        private bool flag = false;
        

        public mediaplayer()
        {
            InitializeComponent();
            this.tsbt_open.Enabled = true;
            this.tsbt_play.Enabled = false;
            this.tsbt_stop.Enabled = false;
            this.tsbt_pause.Enabled = false;
          
        }

        private Boolean Play = false;

        private void PlayOrPause()
        {
            if (m_objMediaControl != null)
            {
                if (Play)
                {
                    m_objMediaControl.Run();
                    m_CurrentStatus = MediaStatus.Running;
                    this.tsbt_play.Enabled = false;
                    this.tsbt_stop.Enabled = true;
                    this.tsbt_pause.Enabled = true;
                    this.flag = true;
                    Play = !Play;
                    this.toolStripButton1.Image = this.imageList1.Images[2];
                }
                else
                {
                    m_objMediaControl.Pause();
                    m_CurrentStatus = MediaStatus.Paused;
                    this.tsbt_play.Enabled = true;
                    this.tsbt_stop.Enabled = true;
                    this.tsbt_pause.Enabled = false;
                    this.flag = false;
                    Play = !Play;
                    this.toolStripButton1.Image = this.imageList1.Images[4];
                }
            }
        }
        //播放
        private void tsbt_play_Click(object sender, EventArgs e)
        {
            PlayOrPause();
        }
        //暂停文件
        private void tsbt_pause_Click(object sender, EventArgs e)
        {
            PlayOrPause();
        }

        //停止播放
        private void tsbt_close_Click(object sender, EventArgs e)
        {
            if (m_objMediaControl != null)
            {
                m_objMediaControl.Stop();
                m_objMediaPosition.CurrentPosition = 0;
                m_CurrentStatus = MediaStatus.Stopped;
                CleanUp();
                this.tsbt_play.Enabled = false;
                this.tsbt_stop.Enabled = false;
                this.tsbt_pause.Enabled = false;
                this.toolStripButton1.Image = this.imageList1.Images[4];
                this.flag = false;
                this.lb_player2.Text = "播放时间:00:00";
                this.trackBar1.Value = 0;
               
                //this.Close();
            }
        }

        private void tsbt_stop_Click(object sender, EventArgs e)
        {
            //m_objMediaControl.Stop();
            //m_objMediaPosition.CurrentPosition = 0;
            //m_CurrentStatus = MediaStatus.Stopped;
            //CleanUp();
            //this.tsbt_play.Enabled = false;
            //this.tsbt_stop.Enabled = false;
            //this.tsbt_pause.Enabled = false;
            //this.flag = false;

        }

       
        //关闭

        private void CleanUp()
        {
            if (m_objMediaControl != null)
                m_objMediaControl.Stop();

            m_CurrentStatus = MediaStatus.Stopped;

            if (m_objMediaEventEx != null)
                m_objMediaEventEx.SetNotifyWindow(0, 0, 0);

            if (m_objVideoWindow != null)
            {
                m_objVideoWindow.Visible = 0;
                m_objVideoWindow.Owner = 0;
            }

            if (m_objMediaControl != null) m_objMediaControl = null;
            if (m_objMediaPosition != null) m_objMediaPosition = null;
            if (m_objMediaEventEx != null) m_objMediaEventEx = null;
            if (m_objMediaEvent != null) m_objMediaEvent = null;
            if (m_objVideoWindow != null) m_objVideoWindow = null;
            if (m_objBasicAudio != null) m_objBasicAudio = null;
            if (m_objFilterGraph != null) m_objFilterGraph = null;
        }
        //清除临时图像

        private void tsbt_open_Click(object sender, EventArgs e)
        {
            openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Media Files|*.mkv;*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";

            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                CleanUp();
               
                m_objFilterGraph = new FilgraphManager();

               
                try
                {
                    m_objFilterGraph.RenderFile(openFileDialog.FileName);
                    m_objBasicAudio = m_objFilterGraph as IBasicAudio;
                    m_objVideoWindow = m_objFilterGraph as IVideoWindow;
                    m_objVideoWindow.Owner = (int)pl_play.Handle;
                    m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                    m_objVideoWindow.SetWindowPosition(pl_play.ClientRectangle.Left,
                        pl_play.ClientRectangle.Top,
                        pl_play.ClientRectangle.Width,
                        pl_play.ClientRectangle.Height);
                  
                }
                catch (Exception ex)
                {
                    MessageBox.Show("该文件不能视频");
                    m_objVideoWindow = null;
                }

                m_objMediaEvent = m_objFilterGraph as IMediaEvent;

                m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
                m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);

                m_objMediaPosition = m_objFilterGraph as IMediaPosition;

                m_objMediaControl = m_objFilterGraph as IMediaControl;
                //播放歌曲名称
                this.Text = "DirectShow - [" + openFileDialog.FileName + "]";
                //开始播放
                m_objMediaControl.Run();
                this.toolStripButton1.Image = this.imageList1.Images[2];
                waveOutSetVolume(0, (System.UInt32)((double)0xffff * (double)this.tb_player1.Value / (double)(this.tb_player1.Maximum - this.tb_player1.Minimum)));
                this.trackBar1.Maximum = 160;
                //设置播放状态
                m_CurrentStatus = MediaStatus.Running;

                this.tsbt_play.Enabled = false;
                this.tsbt_stop.Enabled = true;
                this.tsbt_pause.Enabled = true;


                flag = true;
               // this.hour = 0;
                this.second = 0;
                this.minute = 0;

            }
2012-03-13 22:36
ms1200
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-10-31
得分:0 
这个例子 应该用 applicathin.EnableVisualStyles 这个效率 应该会高一点吧。
2012-11-14 15:01
ms1200
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-10-31
得分:0 
不好意思 回错帖子了。。。
2012-11-14 15:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-363091-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.067028 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved