在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → 简单离线音乐播放器

简单离线音乐播放器

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:8.03M
  • 下载次数:53
  • 浏览次数:708
  • 发布时间:2016-12-30
  • 实例类别:C#语言基础
  • 发 布 人:she's the one
  • 文件格式:.zip
  • 所需积分:2

实例介绍

【实例简介】听音乐
【实例截图】
【核心代码】using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using musicforme;

namespace musicforme
{
    public partial class MainForm : Form
    {
        public MusicContorl MusicContorl = new MusicContorl();
        public MainForm()
        {
            InitializeComponent();
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
        }
        protected override CreateParams CreateParams
        {
            //任务栏放大缩放窗体
            get
            {
                CreateParams cp = base.CreateParams;
                cp.Style = cp.Style | 0x20000;//允许最小化操作
                return cp;
            }
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 13; i )
            {
                this.songListpanel.Controls.Add(MusicContorl.SongLabelList[i]);
                this.MusicContorl.SongLabelList[i].Click = new EventHandler(SongLbl_Click);
                this.MusicContorl.SongLabelList[i].DoubleClick = new EventHandler(SongLbl_DoubleClic);
                
            }
            this.MusicContorl.MusicPlayButton.Click = new System.EventHandler(MusicPlayButton_Click);
            this.Controls.Add(MusicContorl.MusicPlayButton);

            this.Controls.Add(this.MusicContorl.MusicBoxPlayer);

            this.MusicTitlePanel.Controls.Add(this.MusicContorl.MusicNameTitle);
            this.songListpanel.Controls.Add(this.MusicContorl.SongPagelbl);

            this.Controls.Add(this.MusicContorl.MyMusicBar);
            this.Controls.Add(MusicContorl.MyVolumBar);
            this.MusicTitlePanel.Controls.Add(this.MusicContorl.MusicNameTitle);

            var threadMusicBar = new Thread(MusicContorl.ThreadProgressBar) { IsBackground = true };
            threadMusicBar.Start();
            timer1.Start();
            LoadMusicList();
            MusicContorl.VolumeSet();
        }
        private void SongLbl_Click(object sender, EventArgs e)
        {
            this.MusicContorl.SongCursorCtrl(sender);
        }
        private void SongLbl_DoubleClic(object sender,EventArgs e)
        {
            this.MusicContorl.SongPlaySelect(sender);
        }
        private void MusicPlayButton_Click(object sender,EventArgs e)
        {
            MusicContorl.PlayPauseMusic();
        }
        private Point mousePoint;
        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            //鼠标点击位置
            //if (MouseButtons.Left != e.Button) return;
            Point cur = this.PointToScreen(e.Location);
            mousePoint = new Point(cur.X - this.Left, cur.Y - this.Top);
        }

        private void MainForm_MouseMove(object sender, MouseEventArgs e)
        {
            //窗体随鼠标移动
            if (MouseButtons.Left != e.Button) return;
            Point cur = MousePosition;
            this.Location = new Point(cur.X - mousePoint.X, cur.Y - mousePoint.Y);
        }

        private void mFormClose_Click(object sender, EventArgs e)
        {
            //关闭运用
            MusicContorl.pasueMusic();
            Application.Exit();
        }

        private void mFormMin_Click(object sender, EventArgs e)
        {
            //最小化窗体
            this.WindowState = FormWindowState.Minimized;
        }

        private void mFormClose_MouseEnter(object sender, EventArgs e)
        {
            //经过close
            mFormClose.ForeColor = System.Drawing.Color.Yellow;
        }

        private void mFormClose_MouseLeave(object sender, EventArgs e)
        {
            //离开closebtn
            mFormClose.ForeColor = System.Drawing.Color.White;
        }

        private void mFormMin_MouseEnter(object sender, EventArgs e)
        {
            //经过min
            mFormMin.ForeColor = System.Drawing.Color.Yellow;
        }

        private void mFormMin_MouseLeave(object sender, EventArgs e)
        {
            //离开min
            mFormMin.ForeColor = System.Drawing.Color.White;
        }
        int mod=0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            SongTimelbl.Text = MusicContorl.Timelable;
            switch (mod)
            {
                case 1:
                    btnLastMusic.BackgroundImage = global::musicforme.Properties.Resources.preview_on;
                    break;
                case 2:
                    btnNextMusic.BackgroundImage = global::musicforme.Properties.Resources.next_on;
                    break;
                case 3:
                    SongAddPbtn.BackgroundImage = global::musicforme.Properties.Resources.list_on;
                    break;
            }
        }

        private void btnNextMusic_Click(object sender, EventArgs e)
        {
            mod = 2;
            MusicContorl.NextSong();
            timer1.Interval = 200;
            timer1.Start();
        }

        private void btnLastMusic_Click(object sender, EventArgs e)
        {
            mod = 1;
            MusicContorl.LastSong();
            timer1.Interval = 200;
            timer1.Start();
        }
        private void btnLastMusic_MouseDown(object sender, MouseEventArgs e)
        {
            btnLastMusic.BackgroundImage = global::musicforme.Properties.Resources.preview_down;
        }
        private void btnNextMusic_MouseDown(object sender, MouseEventArgs e)
        {
            btnNextMusic.BackgroundImage = global::musicforme.Properties.Resources.next_down;
        }
        private void likeMusic_btn_Click(object sender, EventArgs e)
        {
            
        }

        private void SongAddPbtn_MouseDown(object sender, MouseEventArgs e)
        {
            SongAddPbtn.BackgroundImage = global::musicforme.Properties.Resources.list_down;
        }

        private void SongAddPbtn_Click(object sender, EventArgs e)
        {
            mod = 3;
            timer1.Interval = 200;
            timer1.Start();
            openFileDialog1.InitialDirectory = @"C:\";

            openFileDialog1.RestoreDirectory = false;

            openFileDialog1.Filter = "(*mp3)|*mp3|(*wav)|*.wav|All(*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.Multiselect = true;

            DialogResult R = openFileDialog1.ShowDialog();
            if (R == DialogResult.OK)
            {
                foreach (string SongFileName in openFileDialog1.FileNames)
                {
                    MusicContorl.AddMusic(SongFileName, 1);
                }
            }
        }
        private void LoadMusicList()
        {
            string GetPath = Path.GetFullPath(".\\");
            string FileList = GetPath "MusicList.txt";
            if(File.Exists(FileList))
            {
                StreamReader streamReader = new StreamReader(FileList, System.Text.Encoding.Default);
                string SongPath = "";
                while(true)
                {
                    if((SongPath=streamReader.ReadLine())==null)
                        break;
                    MusicContorl.AddMusic(SongPath,2);
                }
                streamReader.Close();
            }
            else
            {
                StreamWriter streamWriter = new StreamWriter(FileList);
                streamWriter.Close();
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {
            
            MusicContorl.PageSub();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            MusicContorl.PageAdd();
        }
        bool haha=false;
        private void vlumePic_Click(object sender, EventArgs e)
        {
            if(!haha)
            {
                MusicContorl.VolumeDown();
                haha = true;
            }
            else
            {
                MusicContorl.VolumeAdd();
                haha = false;
            }
        }
        int playmode = 1;
        private void picPlayMode_Click(object sender, EventArgs e)
        {
            playmode ;
            MusicContorl.PicPlayMode_Click();
            if (playmode == 1)
            {
                picPlayMode.BackgroundImage = global::musicforme.Properties.Resources.playmode1;
            }
            else if (playmode == 2)
            {
                picPlayMode.BackgroundImage = global::musicforme.Properties.Resources.playmode2;
            }
            else
            {
                picPlayMode.BackgroundImage = global::musicforme.Properties.Resources.playmode3;
                playmode = 0;
            }

        }
        
    }

}

实例下载地址

简单离线音乐播放器

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

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

网友评论

发表评论

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

查看所有0条评论>>

小贴士

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

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

关于好例子网

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

;
报警