在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#多媒体编程 → c#写的暴风影音播放器

c#写的暴风影音播放器

C#多媒体编程

下载此实例
  • 开发语言:C#
  • 实例大小:0.25M
  • 下载次数:136
  • 浏览次数:1773
  • 发布时间:2016-08-19
  • 实例类别:C#多媒体编程
  • 发 布 人:水金
  • 文件格式:.rar
  • 所需积分:1
 相关标签: 播放器 C# 播放 c

实例介绍

【实例简介】c#写的暴风影音播放器
【实例截图】
【核心代码】
public partial class mediaplayer : Form
    {
        private System.ComponentModel.IContainer 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 void tsbt_play_Click(object sender, EventArgs e)
        {
           
            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;
          
        }
        //播放文件

        private void tsbt_pause_Click(object sender, EventArgs e)
        {
            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;
        }
        //暂停播放

        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;
            ToolStripMenuItem_play.Enabled = false;
           
            this.flag = false;
           
        }
        //停止播放

        private void tsbt_close_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;
            ToolStripMenuItem_play.Enabled = true;
            //this.Close();
        }
        //关闭

        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|*.mpg;*.rmvb;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";

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

                m_objFilterGraph = new FilgraphManager();
                m_objFilterGraph.RenderFile(openFileDialog.FileName);

                try
                {
                    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();
                m_CurrentStatus = MediaStatus.Running;

                this.lb_player1.Text = "就绪......";

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


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

            }
        }//打开播放文件

        private void pl_play_SizeChanged(object sender, EventArgs e)
        {
           
              
               
                try
                {
                   
                    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;
                }

               
          
           
        }
        //改变窗口

        [DllImport("Winmm.dll")]
        private static extern int waveOutSetVolume(int hwo, System.UInt32 pdwVolume);
        [DllImport("Winmm.dll")]
        private static extern int waveOutGetVolume(int hwo, System.UInt32 pdwVolume);
        //private static extern int waveOutGetVolume(int hwo, out   System.UInt32 pdwVolume);
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            waveOutSetVolume(0, (System.UInt32)((double)0xffff * (double)this.tb_player1.Value / (double)(this.tb_player1.Maximum - this.tb_player1.Minimum)));
        }
        //控制声音
       
        private int time(bool Flag ,int s)
        {
           string tem = "";
            if (Flag)
            {
               
                s ;
                if (s > 59)
                {
                    s = 0;
                    minute ;
                    if (minute > 59)
                    {
                        minute = 0;
                        hour ;
                    }
                }

                if (hour < 9)
                    tem ="已播放时间:" "0" hour.ToString() ":";
                else
                    tem=hour.ToString() ":";
                if (minute < 9)
                    tem = "0" minute.ToString() ":";
                else
                    tem = minute.ToString() ":";
                if (s < 9)
                    tem = "0" s;
                else
                    tem =s;
                this.lb_player2.Text = tem;
            }
            return s;
        }

        private void tm_play_Tick(object sender, EventArgs e)
        {

            second =time(flag, second);

           
        }

        private void ToolStripMenuItem_open_Click(object sender, EventArgs e)
        {
            this.tsbt_open_Click(sender, e);
            ToolStripMenuItem_exit.Enabled = true;
        }

        private void ToolStripMenuItem_exit_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;
           
        }

        private void ToolStripMenuItem_play_Click(object sender, EventArgs e)
        {
            this.tsbt_play_Click(sender, e);
        }

        private void ToolStripMenuItem_infor_Click(object sender, EventArgs e)
        {
            MessageBox.Show("欢迎来到江财C#技术开发组,想了解更多请与小飞联系prophet_zhh@163.com.....", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void mediaplayer_Load(object sender, EventArgs e)
        {
            //this.skinEngine.SkinFile = "XPOrange.ssk";
        }

    }

标签: 播放器 C# 播放 c

实例下载地址

c#写的暴风影音播放器

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警