在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → winform 视频播放器源码下载(磁力链接)

winform 视频播放器源码下载(磁力链接)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:2.87M
  • 下载次数:152
  • 浏览次数:4356
  • 发布时间:2015-12-11
  • 实例类别:C#语言基础
  • 发 布 人:crazycode
  • 文件格式:.zip
  • 所需积分:2
 相关标签: winform 播放器 视频 下载 播放

实例介绍

【实例简介】

【实例截图】

【核心代码】

namespace VideoPlayer
{
    public partial class Form1 : Form
    {
        ToolTip tip = new ToolTip();
        PlayClass _play = new PlayClass();
        AxPlayer _Player;
        Form maxForm;
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            _Player = axPlayer1;
            axPlayer1.OnBuffer  = new _IPlayerEvents_OnBufferEventHandler(axPlayer1_OnBuffer);
            axPlayer1.OnStateChanged  = new _IPlayerEvents_OnStateChangedEventHandler(axPlayer1_OnStateChanged);
            axPlayer1.OnSeekCompleted  = new _IPlayerEvents_OnSeekCompletedEventHandler(axPlayer1_OnSeekCompleted);
            axPlayer1.OnOpenSucceeded  = new EventHandler(axPlayer1_OnOpenSucceeded);
            axPlayer1.OnDownloadCodec  = new _IPlayerEvents_OnDownloadCodecEventHandler(axPlayer1_OnDownloadCodec);
            axPlayer1.SetCustomLogo(Properties.Resources.logo.GetHbitmap().ToInt32());  //自定义logo
            axPlayer1.SetVolume(50);
            colorSlider2.Enabled = false;
            TransparentOperation();
            this.Resize  = new EventHandler(FormResize);
            
        }
        void TransparentOperation()
        {


            //pic_play_pause.Parent=panelbottom;
      
           // colorSlider1.Parent = panelbottom;

          
        }

        #region  axPlayer事件处理程序
        /// <summary>
        /// axPlayer的鼠标、键盘事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void axPlayer1_OnMessage(object sender, _IPlayerEvents_OnMessageEvent e)
        {
            //throw new NotImplementedException();
            switch (e.nMessage)
            {
                case conf.WM_LBUTTONDOWN:
                    MoveForm();
                    break;
                case conf.WM_RBUTTONDOWN:
                     int tempstatus=axPlayer1.GetState();

                if (axPlayer1.GetState()== 5)
                {
                    contextMenuStrip1.Items["playpause"].Text = "暂停";
                }
                else
                {
                    contextMenuStrip1.Items["playpause"].Text = "播放";
                }
                contextMenuStrip1.Show(axPlayer1, axPlayer1.PointToClient(Cursor.Position));
                break;
                case conf.WM_LBUTTONDBLCLK:
                maxScreen();break;
                default: break;
	        }

            //switch (e.nMessage)
            //{

            //    case conf.WM_LBUTTONDOWN:
            //        //Functions.moveForm(this.Handle);//拖动窗口SendMessage   这里按下默认拖动窗口
            //        //VM_X = Control.MousePosition.X; //记录鼠标此刻位置
            //        //VM_Y = Control.MousePosition.Y;
            //        //System.Threading.Thread.Sleep(300); //300毫秒后执行interval时钟事件
            //        //interval.Enabled = true;
            //        //Functions.moveForm(this.Handle);
            //        break;
            //    case conf.WM_LBUTTONUP:
            //        interval.Enabled = false;//鼠标弹起静止时钟 减耗内存
            //        break;
            //    case conf.WM_LBUTTONDBLCLK://双击全屏事件
            //        MessageBox.Show("双击");
            //        interval.Enabled = false;
            //        //maxScreen();


            //        break;
            //    case conf.WM_RBUTTONDOWN:
            //        MessageBox.Show("右键单击");
            //        //rightButtonMenu.Show(new Point(Control.MousePosition.X, Control.MousePosition.Y));
            //        break;
            //    default:
            //        break;

            //}
        }
        /// <summary>
        /// 格式不支持,需要下载解码器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void axPlayer1_OnDownloadCodec(object sender, _IPlayerEvents_OnDownloadCodecEvent e)
        {
            MessageBox.Show("需要解码器:" e.strCodecPath);
        }
        /// <summary>
        /// 文件打开完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void axPlayer1_OnOpenSucceeded(object sender, EventArgs e)
        {
            label1.Text = "00:00:00";
            label2.Text = TimeToString(TimeSpan.FromMilliseconds(axPlayer1.GetDuration()));
            colorSlider2.Enabled = true;
            colorSlider2.Maximum = axPlayer1.GetDuration();
            timer1.Start();
        }
        /// <summary>
        /// 跳转指定位置完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void axPlayer1_OnSeekCompleted(object sender, _IPlayerEvents_OnSeekCompletedEvent e)
        {
            //throw new NotImplementedException();
        }
        /// <summary>
        /// 播放器状态改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void axPlayer1_OnStateChanged(object sender, _IPlayerEvents_OnStateChangedEvent e)
        {
            if (e.nNewState == 0)  //就绪
            {
                //初始化

               
            }
            switch (e.nNewState)
            {
                case (int)PlayClass.PLAY_STATE.PS_READY:
                     colorSlider2.Maximum = 100;
                colorSlider2.Value = 0;
                colorSlider2.Enabled = false;
                label1.Text = "00:00:00";
                label2.Text = "00:00:00";
                label3.Text = "准备就绪";
                timer1.Stop();
                break;
                case (int)PlayClass.PLAY_STATE.PS_OPENING: label3.Text = "正在打开"; break;
                case (int)PlayClass.PLAY_STATE.PS_PLAY:
                case (int)PlayClass.PLAY_STATE.PS_PLAYING:
                    label3.Text = "正在播放";
                    pic_play_pause.ErrorImage = VideoPlayer.Properties.Resources.pause;
                ChangErrPic(pic_play_pause);break;
                case (int)PlayClass.PLAY_STATE.PS_PAUSED:
                case (int)PlayClass.PLAY_STATE.PS_PAUSING: label3.Text = "暂停播放"; pic_play_pause.ErrorImage = VideoPlayer.Properties.Resources.play;
                    ChangErrPic(pic_play_pause);break;
                case (int)PlayClass.PLAY_STATE.PS_CLOSING:
                     pic_play_pause.ErrorImage = VideoPlayer.Properties.Resources.play;
                ChangErrPic(pic_play_pause);break;
                default:
                    break;
            }
            Console.WriteLine("播放器状态:" e.nNewState);
        }
        /// <summary>
        /// 缓冲
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void axPlayer1_OnBuffer(object sender, _IPlayerEvents_OnBufferEvent e)
        {
            if (e.nPercent != 100)
            {
                label3.Text = "正在缓冲...("   e.nPercent   "%)";
            }
            else
            {
                label3.Text = "正在播放"; ;
            }
        }



        #endregion

        /// <summary>
        /// 打开本地文件
        /// </summary>
        private void openfile()
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "mp4|*.mp4|avi|*.avi|rm|*.rm|rmvb|*.rmvb|flv|*.flv|xr|*.xr|所有文件|*.*";
                ofd.Multiselect = false;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    axPlayer1.Open(ofd.FileName);
                }
            }
        }
        /// <summary>
        /// 打开网络文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            using (Form2 f = new Form2())
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    axPlayer1.Open(f.URL);
                    label3.Text = "正在打开.";
                }
            }
        }

        private void PlayOrPause()
        {

            int tempstatus=_Player.GetState();
            if (tempstatus == 0)
            {
                using (Form2 f = new Form2())
                {
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        axPlayer1.Open(f.URL);
                    }
                }
            }
            else if (tempstatus == 5 || tempstatus == 3)
            {
                if (axPlayer1.GetState() == 5)  //播放-暂停
                {
                    axPlayer1.Pause();
                }
                else
                {
                    axPlayer1.Play();
                }
            }
            
        }
        private void Stop()
        {
            axPlayer1.Close();
        }
        /// <summary>
        /// 全屏
        /// </summary>
        public void maxScreen()
        {

            if (_play.isScreen == false)
            {
                //记录播放器尺寸位置
                _play.position.Top = _Player.Top;
                _play.position.Left = _Player.Left;
                _play.position.Width= _Player.Width;
                _play.position.Height= _Player.Height;
                maxForm = new Form();//实例化新窗口设置屏幕设备大小 并置于播放器父窗口
                maxForm.Width = Screen.PrimaryScreen.Bounds.Width;
                maxForm.Height = Screen.PrimaryScreen.Bounds.Height;
                maxForm.FormBorderStyle = FormBorderStyle.None;
                _Player.Parent = maxForm;
                maxForm.Show();
                
                _play.isScreen = true;
                Win32.SetParent((int)_Player.Handle, (int)maxForm.Handle);
                _Player.Left = 0;
                _Player.Top = 0;
                _Player.Width = Screen.PrimaryScreen.Bounds.Width;
                _Player.Height = Screen.PrimaryScreen.Bounds.Height;
                label3.Text = "开启全屏播放";
            }
            else
            {
                _Player.Parent = this;
                _Player.Dock = DockStyle.Fill;
                _Player.BringToFront();
                _play.isScreen = false;
                Win32.SetParent((int)_Player.Handle, (int)this.Handle);
                _Player.Top = _play.position.Top paneltop.Height;
                _Player.Left = _play.position.Left;
                _Player.Width = _play.position.Width;
                _Player.Height = _play.position.Height - paneltop.Height-panelbottom.Height-panelpro.Height;
                maxForm.Close();
                label3.Text = "取消全屏播放";
            }
        }
        /// <summary>
        /// 定时更新进度条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = TimeToString(TimeSpan.FromMilliseconds(axPlayer1.GetPosition()));
            colorSlider2.Value = axPlayer1.GetPosition() <= 0 ? 0 : axPlayer1.GetPosition();
            
        }

        /// <summary>
        /// 时间格式转换
        /// </summary>
        /// <param name="span"></param>
        /// <returns></returns>
        string TimeToString(TimeSpan span)
        {
            return span.Hours.ToString("00")   ":"  
            span.Minutes.ToString("00")   ":"  
            span.Seconds.ToString("00");
        }
        void MoveForm()
        {
            Functions.moveForm(this.Handle);//拖动窗口SendMessage   这里按下默认拖动窗口
            _play.VM_X = Control.MousePosition.X; //记录鼠标此刻位置
            _play.VM_Y = Control.MousePosition.Y;
            System.Threading.Thread.Sleep(300); //300毫秒后执行interval时钟事件
        
        }



        //以下具体设置 如APlayer.SetConfig()方法的用法请参见  开发文档chm

        /// <summary>
        /// 字幕   
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 显示字母ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((sender as ToolStripMenuItem).Text == "显示字幕")
            {
                (sender as ToolStripMenuItem).Text = "隐藏字幕";
                axPlayer1.SetConfig(504, "1");
            }
            else
            {
                (sender as ToolStripMenuItem).Text = "显示字幕";
                axPlayer1.SetConfig(504, "0");
            }
        }
        private void playpause_Click(object sender, EventArgs e)
        {
            
                PlayOrPause();
   
        }

        private void 停止toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            Stop();
        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 32)
            {
                PlayOrPause();
            }
            else
            {
                Console.WriteLine(e.KeyChar);
            }
            
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button==MouseButtons.Left)
            {
                MoveForm();
            }
        }

        private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                MoveForm();
            }
        }

        private void pic_play_pause_Click(object sender, EventArgs e)
        {
            PlayOrPause();
        }

        private void Pic_MouseEnter(object sender, EventArgs e)
        {
            ChangePic((PictureBox)sender, PlayClass.MouseStaue.enter);
        }
        private void pic_MouseUp(object sender, MouseEventArgs e)
        {
            ChangePic((PictureBox)sender, PlayClass.MouseStaue.enter);
        }
        private void Pic_MouseLeave(object sender, EventArgs e)
        {
            ChangePic((PictureBox)sender, PlayClass.MouseStaue.level);
        }
        private void Pic_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ChangePic((PictureBox)sender, PlayClass.MouseStaue.down);
            }
        }
        void ChangErrPic(PictureBox pic)
        {
            Rectangle rectangle = pic.RectangleToClient(this.ClientRectangle);
            if (rectangle.Contains(MousePosition))
            {
                ChangePic(pic, PlayClass.MouseStaue.enter);
            }
            else
            {
                ChangePic(pic, PlayClass.MouseStaue.normal);
            }
        }
        void ChangePic(PictureBox pic, PlayClass.MouseStaue status)
        {
            pic.Image = ImageHelper.GetImageByAverageIndex(pic.ErrorImage, 4, (int)status);
        }
        void Move_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                MoveForm();
            }
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            Rounding(7);

        }
        void FormResize(object sender, EventArgs e)
        {
            _Player.Width = this.Width;
            _Player.Height = this.Height - paneltop.Height - panelbottom.Height - panelpro.Height;
            picclose.Left = this.Width - picclose.Width - 1;
            picmax.Left = picclose.Left - picmax.Width;
            piclist.Left = this.Width - piclist.Width - 8;
            picopen.Left = piclist.Left - picopen.Width;
            picsavapic.Left = picopen.Left - picsavapic.Width;
            pic_play_pause.Left = (this.Width - pic_play_pause.Width) / 2;
            picstop.Left = pic_play_pause.Left - picstop.Width - 10;
            picsound.Left = pic_play_pause.Left   pic_play_pause.Width   10;
            colorSlidersound.Left = picsound.Left   picsound.Width   5;

        }
        public bool Rounding(int angle = 0)
        {
            int hRgn;
            if (angle == 0)
            {
                angle = 5;
            }

            hRgn = Win32.CreateRoundRectRgn(0, 0, this.Width, this.Height, angle, angle);
            if (hRgn == 0)
            {
                return false;
            }
            if (Win32.SetWindowRgn(this.Handle.ToInt32(), hRgn, true) == 0)
            {
                return false;
            }
            Win32.DeleteObject(hRgn);
            return true;
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Stop();
        }


        private void pictureBox4_Click(object sender, EventArgs e)
        {
            openfile();
        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            SavePic();
        }
        private void SavePic()
        {
            axPlayer1.SetConfig(702, Application.StartupPath   "\\截图.bmp");
        }

        private void 截图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SavePic();
        }

        private void colorSlider1_Scroll(object sender, ScrollEventArgs e)
        {
            axPlayer1.SetVolume(colorSlidersound .Value* 10);  //10倍
        }

        private void colorSlider2_MouseHover(object sender, EventArgs e)
        {

            tip.Show(TimeToString(TimeSpan.FromMilliseconds(colorSlider2.Value)), colorSlider2, 2000);
        }

        private void colorSlider2_Scroll(object sender, ScrollEventArgs e)
        {
            axPlayer1.SetPosition(colorSlider2.Value);
            label1.Text = TimeToString(TimeSpan.FromMilliseconds(colorSlider2.Value));
        }

        private void picmax_Click(object sender, EventArgs e)
        {
            MaxOrMin();
        }
        void MaxOrMin()
        {
            if (this.Width != Screen.PrimaryScreen.WorkingArea.Width || this.Height != Screen.PrimaryScreen.WorkingArea.Height)
            {
                _play.position.Left = this.Left;
                _play.position.Top = this.Top;
                _play.position.Width = this.Width;
                _play.position.Height = this.Height;
                this.Left = this.Top = 0;
                this.Width = Screen.PrimaryScreen.WorkingArea.Width;
                this.Height = Screen.PrimaryScreen.WorkingArea.Height;
            }
            else
            {
                this.Left = _play.position.Left;
                this.Top = _play.position.Top;
                this.Width = _play.position.Width;
                this.Height = _play.position.Height;
            }
        }

        private void lbltitle_DoubleClick(object sender, EventArgs e)
        {
            Console.WriteLine(lbltitle.Text);
        }

        private void lbltitle_Click(object sender, EventArgs e)
        {
            Console.WriteLine(lbltitle.Text);
        }

        private void paneltop_DoubleClick(object sender, EventArgs e)
        {
            Console.WriteLine(lbltitle.Text);           
        }




        

    }
}

实例下载地址

winform 视频播放器源码下载(磁力链接)

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

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

网友评论

第 1 楼 jjtailing 发表于: 2017-08-21 15:19 05
好东西,谢谢分享

支持(0) 盖楼(回复)

第 2 楼 许志向 发表于: 2017-12-06 10:21 19
差评,不能用

支持(0) 盖楼(回复)

发表评论

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

查看所有2条评论>>

小贴士

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

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

关于好例子网

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

;
报警