基本信息
源码名称:DMPlayer播放器 完整源代码
源码大小:23.40M
文件格式:.7z
开发语言:C#
更新时间:2018-10-11
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍


 

#region 绘制主界面
        SolidBrush sb = new SolidBrush(Color.FromArgb(32, 191, 99));
        protected override void OnPaint(PaintEventArgs e)
        {
            //设置高质量插值法
            e.Graphics.InterpolationMode = InterpolationMode.Bilinear;
            //设置高质量,低速度呈现平滑程度
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            e.Graphics.FillRectangle(sb, -1, -1, Width 30, Height 30);

            if (PlayerStae!= PlayState.Stop)
            {
                //绘制播放标题
                if (CurrentFile != null && CurrentFile.FileName.Trim() != "")
                {
                    string Temp = CurrentFile.FileName;
                    int wit = Convert.ToInt32(e.Graphics.MeasureString(Temp, TitleFont).Width); ;
                    while (wit > Width - 250)
                    {
                        Temp = Temp.Substring(0, Temp.Length - 2);
                        wit = Convert.ToInt32(e.Graphics.MeasureString(Temp, TitleFont).Width);
                    }
                    e.Graphics.DrawString(Temp, TitleFont, new SolidBrush(Color.White), new Point(Width / 2 - wit / 2, 12));
                }
            }
        }
        #endregion

        #region 界面操作
        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            if (op.ShowDialog() == DialogResult.OK)
            {
                PlayFile p = new PlayFile();
                p.FileUrl = op.FileName;
                p.FileName = op.SafeFileName;
                Play(p);
            }
        }
        #endregion

        #region 界面效果
        private void btn_MouseEnter(object sender, EventArgs e)
        {
            DMSkin.Controls.DMLabel dm = (DMSkin.Controls.DMLabel)sender;
            dm.DM_Color = Color.FromArgb(192, 255, 192);
        }

        private void btn_MouseLeave(object sender, EventArgs e)
        {
            DMSkin.Controls.DMLabel dm = (DMSkin.Controls.DMLabel)sender;
            dm.DM_Color = Color.White;
        }

        private void Listbtn_MouseEnter(object sender, EventArgs e)
        {
            DMSkin.Controls.DMLabel dm = (DMSkin.Controls.DMLabel)sender;
            dm.DM_Color = Color.SeaGreen;
        }

        private void Listbtn_MouseLeave(object sender, EventArgs e)
        {
            DMSkin.Controls.DMLabel dm = (DMSkin.Controls.DMLabel)sender;
            dm.DM_Color = Color.MediumSeaGreen;
        }
        #endregion

        #region 播放
        bool IsMouseDown = false;//鼠标按下
        int ToPostion = 0;//目标进度
        int CurrentLength = 0;
        double CurrentPosition = 0.0;
        PlayFile CurrentFile = new PlayFile();
        public List<PlayFile> PlayLists = new List<PlayFile>();
        public void Play(PlayFile file)
        {
            Player.SetConfig(2201,API.SavePath file.FileName.Trim() ".dm");
            CurrentFile = file;
            Player.Close();
            InitPlay();
            Player.Open(file.FileUrl);
            btnPlay.DM_Key = DMSkin.Controls.DMLabelKey.暂停;
            PlayerStae = PlayState.Play;
            this.Invalidate();
        }
        public void TurnPlayPage()
        {
            PlayListView.SelectedIndex = 0;
        }
        Font TitleFont = new Font("微软雅黑", 12, FontStyle.Bold);

        public void Play()
        {
            Player.Play();
            PlayerStae = PlayState.Play;
            btnPlay.DM_Key = DMSkin.Controls.DMLabelKey.暂停;
        }
        public void Stop()
        {
            InitPlay();
            CurrentFile.FileName = "";
            labTime.Text = "00:00:00/00:00:00";
            Player.Close();
            PlayerStae = PlayState.Stop;
            this.Invalidate();
        }
        /// <summary>
        /// 往后
        /// </summary>
        private void PlayBack()
        {
            int index = Convert.ToInt32(CurrentPosition);
            int toindex = index - 4000;
            Player.SetPosition(toindex);
            CurrentPosition = Convert.ToDouble(Player.GetPosition());
        }
        /// <summary>
        /// 往前
        /// </summary>
        private void PlayGo()
        {
            int index = Convert.ToInt32(CurrentPosition);
            int toindex = index 4000;
            Player.SetPosition(toindex);
            CurrentPosition = Convert.ToDouble(Player.GetPosition());
        }
        /// <summary>
        /// 上一首
        /// </summary>
        private void PlayPrevious()
        {
            
        }
        /// <summary>
        /// 下一首
        /// </summary>
        private void PlayNext()
        {

        }
        public int GetBufferProgress()
        {
            //int IDS =;
            return Player.GetBufferProgress();
        }
        public int GetVolume() 
        {
            return Player.GetVolume();
        }
        public void SetVolume(int num)
        {
            Player.SetVolume(num);
            this.toolTip.Show(Convert.ToInt32(dmVolumeProgress.DM_Value).ToString(), dmVolumeProgress);
        }
        public void Pause()
        {
            Player.Pause();
            PlayerStae = PlayState.Pause;
            btnPlay.DM_Key = DMSkin.Controls.DMLabelKey.播放;
        }
        public void InitPlay()
        {
            btnPlay.DM_Key = DMSkin.Controls.DMLabelKey.播放;
            CurrentLength = 0;
            CurrentPosition = 0.0;
            ToPostion = 0;
            dmProgressBar.DM_Value = 0;
        }
        /// <summary>
        /// 时间转换,将秒转换为对应的   mm:ss
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static string ConvertTime(int time)
        {
            string musicTime = "00:00";
            if (time > 0)
            {
                int minute = time / 60;
                int seconds = time % 60;
                musicTime = (minute < 10 ? "0" minute.ToString() : minute.ToString()) ":" (seconds < 10 ? "0" seconds.ToString() : seconds.ToString());
            }
            return musicTime;
        }
        public void ShowTime()
        {
            string str1 = ConvertTime(Player.GetPosition() / 1000);
            string str2 = ConvertTime(Player.GetDuration() / 1000);
            if (str1.IndexOf(".") >= 0)
            {
                str1 = str1.Substring(0, str1.LastIndexOf("."));
            }
            if (str2.IndexOf(".") >= 0)
            {
                str2 = str2.Substring(0, str2.LastIndexOf("."));
            }
            labTime.Text = str1 "/" str2;
        }
        bool Full = false;
        Rectangle Nor = new Rectangle(0, 0, 0, 0);
        //全屏
        public void FullScreen()
        {
            if (Full)
            {
                this.WindowState = FormWindowState.Normal;
                axPlayer.Parent = tabPage1;
                axPlayer.BringToFront();
                axPlayer.Location = Nor.Location;
                axPlayer.Size = Nor.Size;
                Full = false;
            }
            else
            {
                Nor = new Rectangle(axPlayer.Location, axPlayer.Size);
                axPlayer.Parent = this;
                this.WindowState = FormWindowState.Maximized;
                axPlayer.BringToFront();
                axPlayer.Location = new Point(0, 0);
                axPlayer.Size = Size;
                Full = true;
            }
            axPlayer.Focus();
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            if (PlayerStae == PlayState.Play)//播放中
            {
                if (!IsMouseDown)//没有拖动
                {
                    CurrentLength = Player.GetDuration();
                    if (CurrentLength == 0)
                    {
                        return;
                    }
                    CurrentPosition = Convert.ToDouble(Player.GetPosition());
                    
                    dmProgressBar.DM_Value = CurrentPosition / Convert.ToDouble(CurrentLength) * 100.0;
                    dmProgressBar.Invalidate();
                    ShowTime();
                }
            }
        }

        private void dmProgressBar_MouseUp(object sender, MouseEventArgs e)
        {
            //进度条鼠标抬起
            IsMouseDown = false;
            if (ToPostion != 0)
            {
                Player.SetPosition(ToPostion);
            }
        }
        private void dmProgressBar_MouseDown(object sender, MouseEventArgs e)
        {
            //进度条鼠标按下
            if (dmProgressBar.Cursor==Cursors.Hand)
            {
                IsMouseDown = true;
            }
        }

        private void dmProgressBar_MouseMove(object sender, MouseEventArgs e)
        {
            //鼠标拖动
            if (IsMouseDown)//鼠标按下
            {
                ToPostion = Convert.ToInt32(dmProgressBar.DM_Value / 100.0 * Convert.ToDouble(Player.GetDuration()));
            }
        }

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

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            ///上一首
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            ///播放
            if (PlayerStae == PlayState.Play)
            {
                Pause();
                btnPlay.DM_Key = DMSkin.Controls.DMLabelKey.播放;
            }
            else
            {
                Play();
                btnPlay.DM_Key = DMSkin.Controls.DMLabelKey.暂停;
            }
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            //下一首

        }
        private void btnMax_Click(object sender, EventArgs e)
        {
            //最大化
            FullScreen();
        }
        

        
        #endregion

        #region 播放器事件
        private void PlayList_ItemClick(object sender, EventArgs e)
        {
            if (Player != null)
            {
                Item it = (Item)sender;
                PlayFile p = new PlayFile();
                p.FileUrl = it.Url;
                p.FileName = it.Text;
                Play(p);
                TurnPlayPage();
            }
        }


        private void axPlayer_OnMessage(object sender, AxAPlayer3Lib._IPlayerEvents_OnMessageEvent e)
        {

            switch (e.nMessage)
            {

                case DMSkin.Win32.WM_LBUTTONDBLCLK://双击
                    FullScreen();
                    break;
                case DMSkin.Win32.WM_LBUTTONDOWN:
                    //右键菜单
                    break;
                default:
                    break;

            }
        }
        Rectangle LastRect;
        bool Max = false;
        /// <summary>
        /// 双击 最大化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (!Max)
            {
                LastRect = new Rectangle(Location, Size);
                Width = Screen.PrimaryScreen.Bounds.Width;
                Height = Screen.PrimaryScreen.Bounds.Height;
                Location = new Point(0, 0);
                Max = true;
            }
            else
            {
                Width = LastRect.Width;
                Height = LastRect.Height;
                Location = LastRect.Location;
                Max = false;
            }
            axPlayer.Focus();
        }
        #endregion

        #region 播放列表-操作
        /// <summary>
        /// 新增单曲到播放列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            if (op.ShowDialog() == DialogResult.OK)
            {
                PlayFile p = new PlayFile();
                p.FileUrl = op.FileName;
                p.FileName = op.SafeFileName;
                PlayListAdd(p);
                InitPlayListView();
            }
        }

        /// <summary>
        /// 重绘 歌曲列表
        /// </summary>
        public void InitPlayListView()
        {
            PlayListControl.Items.Clear();
            if (PlayLists != null)
            {
                int indexY = 0;
                for (int i = 0; i < PlayLists.Count; i )
                {
                    Item it = new Item();
                    it.Bounds = new Rectangle(0, indexY, 1920, 50);
                    it.Text = PlayLists[i].FileName;
                    it.Url = PlayLists[i].FileUrl;
                    it.OnLine = PlayLists[i].FileOnLine;
                    it.MouseBackColor = Color.FromArgb(224, 224, 224);
                    it.ForeColor = Color.MediumSeaGreen;
                    PlayListControl.Items.Add(it);
                    indexY = 50;
                }
            }
        }

        /// <summary>
        /// 清空播放列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnListClear_Click(object sender, EventArgs e)
        {
            PlayLists.Clear();
            InitPlayListView();
        }

        //选择文件夹 搜索
        private void btnListFileWork_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fd = new FolderBrowserDialog();
            if (fd.ShowDialog() == DialogResult.OK)
            {
                API.LoopFolder(fd.SelectedPath, (System.IO.FileInfo file) =>
                {
                    PlayFile p = new PlayFile();
                    p.FileUrl = file.FullName;
                    p.FileName = file.Name;
                    PlayListAdd(p);
                });
                InitPlayListView();
            }
        }

        public void PlayListAdd(PlayFile p)
        {
            if (PlayLists == null)
            {
                PlayLists = new List<PlayFile>();
            }
            for (int i = 0; i < API.CanPlayFile.Count; i )
            {
                if (p.FileName.ToLower().IndexOf(API.CanPlayFile[i]) >= 0)
                {
                    PlayLists.Add(p);
                }
            }
        }

        private void btnListFileWeb_Click(object sender, EventArgs e)
        {
            Open op = new Open(this);
            op.Show();
        }

        /// <summary>
        /// 切换屏幕比
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dmComboBox_Scrren_DM_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (dmComboBox_Scrren.DM_SelectItem.Text == "铺满窗口")
            {
                Player.SetConfig(207, "Set");
            }
            else
            {
                Player.SetConfig(204, dmComboBox_Scrren.DM_SelectItem.Text);
            }
            TurnPlayPage();
        }

        private void axPlayer_OnStateChanged(object sender, AxAPlayer3Lib._IPlayerEvents_OnStateChangedEvent e)
        {
            if (e.nNewState == 0)
            {
                Stop();
            }
        }
        #endregion

        #region 声音操作
        bool IsVolumeMouseDown = false;
        private void dmVolumeProgress_MouseDown(object sender, MouseEventArgs e)
        {
            //进度条鼠标按下
            if (dmVolumeProgress.Cursor == Cursors.Hand)
            {
                IsVolumeMouseDown = true;
            }
        }

        private void dmVolumeProgress_MouseMove(object sender, MouseEventArgs e)
        {
            //鼠标拖动
            if (IsVolumeMouseDown)//鼠标按下
            {
                SetVolume(Convert.ToInt32(dmVolumeProgress.DM_Value));
            }
        }
       

        private void dmVolumeProgress_MouseUp(object sender, MouseEventArgs e)
        {
            //进度条鼠标抬起
            IsVolumeMouseDown = false;
            SetVolume(Convert.ToInt32(dmVolumeProgress.DM_Value));
        }
        /// <summary>
        /// 缓冲
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axPlayer_OnBuffer(object sender, AxAPlayer3Lib._IPlayerEvents_OnBufferEvent e)
        {
            dmProgressBar.DM_BufferValue = e.nPercent;
        }
        #endregion