C# WinForm 音乐播放器源码

目前网络上很多C#做的音乐播放器,但是功能不尽人意。本人通过网上的播放器源码结合自身的知识做出一个比较好的播放器,供大家交流。如图:

C# WinForm 音乐播放器源码_第1张图片

以下是播放器界面代码,新建一个项目CmTTPlayer,窗体文件名为Frm;

namespace CmTTPlayer
{
    partial class Frm
    {
        ///
        /// 必需的设计器变量。
        ///
        private System.ComponentModel.IContainer components = null;

        ///
        /// 清理所有正在使用的资源。
        ///
        /// 如果应释放托管资源,为 true;否则为 false。
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        ///
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        ///
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Frm));
            this.ribbonClientPanel1 = new DevComponents.DotNetBar.Ribbon.RibbonClientPanel();
            this.slider1 = new DevComponents.DotNetBar.Controls.Slider();
            this.tabControl1 = new DevComponents.DotNetBar.TabControl();
            this.tabControlPanel3 = new DevComponents.DotNetBar.TabControlPanel();
            this.lvMusicList = new System.Windows.Forms.ListView();
            this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
            this.tabItem3 = new DevComponents.DotNetBar.TabItem(this.components);
            this.tabControlPanel1 = new DevComponents.DotNetBar.TabControlPanel();
            this.tabItem1 = new DevComponents.DotNetBar.TabItem(this.components);
            this.tabControlPanel2 = new DevComponents.DotNetBar.TabControlPanel();
            this.tabItem2 = new DevComponents.DotNetBar.TabItem(this.components);
            this.statusStrip1 = new System.Windows.Forms.StatusStrip();
            this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
            this.tsmiOpenMusic = new System.Windows.Forms.ToolStripMenuItem();
            this.tsmiOpenFolderMusic = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
            this.tsmiOpenUrlMusic = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripDropDownButton2 = new System.Windows.Forms.ToolStripDropDownButton();
            this.panel2 = new System.Windows.Forms.Panel();
            this.btnPre = new DevComponents.DotNetBar.ButtonX();
            this.btnLast = new DevComponents.DotNetBar.ButtonX();
            this.btnPlayOrPause = new DevComponents.DotNetBar.ButtonX();
            this.btnStop = new DevComponents.DotNetBar.ButtonX();
            this.pnlTop = new System.Windows.Forms.Panel();
            this.lblMin = new System.Windows.Forms.Label();
            this.lblExit = new System.Windows.Forms.Label();
            this.progressBarX1 = new DevComponents.DotNetBar.Controls.ProgressBarX();
            this.chkAudioOnOff = new System.Windows.Forms.CheckBox();
            this.lblCurrentPosition = new System.Windows.Forms.Label();
            this.lblDuration = new System.Windows.Forms.Label();
            this.lblMusicName = new System.Windows.Forms.Label();
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.tsmenuDeleteChangeMusic = new System.Windows.Forms.ToolStripMenuItem();
            this.删除重复歌曲ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripSeparator();
            this.tsmenuClearList = new System.Windows.Forms.ToolStripMenuItem();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
            this.ribbonClientPanel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tabControlPanel3.SuspendLayout();
            this.statusStrip1.SuspendLayout();
            this.panel2.SuspendLayout();
            this.pnlTop.SuspendLayout();
            this.contextMenuStrip1.SuspendLayout();
            this.SuspendLayout();
            this.ribbonClientPanel1.CanvasColor = System.Drawing.SystemColors.Control;
            this.ribbonClientPanel1.Controls.Add(this.slider1);
            this.ribbonClientPanel1.Controls.Add(this.tabControl1);
            this.ribbonClientPanel1.Controls.Add(this.statusStrip1);
            this.ribbonClientPanel1.Controls.Add(this.panel2);
            this.ribbonClientPanel1.Controls.Add(this.pnlTop);
            this.ribbonClientPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ribbonClientPanel1.Location = new System.Drawing.Point(0, 0);
            this.ribbonClientPanel1.Name = "ribbonClientPanel1";
            this.ribbonClientPanel1.Size = new System.Drawing.Size(298, 545);
            this.ribbonClientPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground2;
            this.ribbonClientPanel1.Style.BackColorGradientAngle = 90;
            this.ribbonClientPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;
            this.ribbonClientPanel1.Style.BackgroundImagePosition = DevComponents.DotNetBar.eStyleBackgroundImage.Tile;
            this.ribbonClientPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid;
            this.ribbonClientPanel1.Style.BorderBottomWidth = 1;
            this.ribbonClientPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder;
            this.ribbonClientPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid;
            this.ribbonClientPanel1.Style.BorderLeftWidth = 1;
            this.ribbonClientPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid;
            this.ribbonClientPanel1.Style.BorderRightWidth = 1;
            this.ribbonClientPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid;
            this.ribbonClientPanel1.Style.BorderTopWidth = 1;
            this.ribbonClientPanel1.Style.Class = "RibbonClientPanel";
            this.ribbonClientPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
            this.ribbonClientPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemText;
            this.ribbonClientPanel1.StyleMouseDown.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemPressedBackground2;
            this.ribbonClientPanel1.StyleMouseDown.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemPressedBackground;
            this.ribbonClientPanel1.StyleMouseDown.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemPressedBorder;
            this.ribbonClientPanel1.StyleMouseDown.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemPressedText;
            this.ribbonClientPanel1.StyleMouseOver.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemHotBackground2;
            this.ribbonClientPanel1.StyleMouseOver.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemHotBackground;
            this.ribbonClientPanel1.StyleMouseOver.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemHotBorder;
            this.ribbonClientPanel1.StyleMouseOver.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemHotText;
            this.ribbonClientPanel1.TabIndex = 0;
            this.slider1.BackColor = System.Drawing.Color.Transparent;
            this.slider1.Location = new System.Drawing.Point(123, 523);
            this.slider1.Maximum = 1000;
            this.slider1.Name = "slider1";
            this.slider1.Size = new System.Drawing.Size(161, 20);
            this.slider1.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;
            this.slider1.TabIndex = 3;
            this.slider1.Text = "音量:";
            this.slider1.Value = 1000;
            this.slider1.ValueChanged += new System.EventHandler(this.slider1_Scroll);
            this.tabControl1.CanReorderTabs = true;
            this.tabControl1.Controls.Add(this.tabControlPanel3);
            this.tabControl1.Controls.Add(this.tabControlPanel1);
            this.tabControl1.Controls.Add(this.tabControlPanel2);
            this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControl1.ForeColor = System.Drawing.SystemColors.ControlText;
            this.tabControl1.Location = new System.Drawing.Point(0, 96);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedTabFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold);
            this.tabControl1.SelectedTabIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(298, 427);
            this.tabControl1.TabIndex = 9;
            this.tabControl1.TabLayoutType = DevComponents.DotNetBar.eTabLayoutType.FixedWithNavigationBox;
            this.tabControl1.Tabs.Add(this.tabItem3);
            this.tabControl1.Text = "tabControl1";
            this.tabControlPanel3.Controls.Add(this.lvMusicList);
            this.tabControlPanel3.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControlPanel3.Location = new System.Drawing.Point(0, 26);
            this.tabControlPanel3.Name = "tabControlPanel3";
            this.tabControlPanel3.Padding = new System.Windows.Forms.Padding(1);
            this.tabControlPanel3.Size = new System.Drawing.Size(298, 401);
            this.tabControlPanel3.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));
            this.tabControlPanel3.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));
            this.tabControlPanel3.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;
            this.tabControlPanel3.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(96)))), ((int)(((byte)(128)))), ((int)(((byte)(88)))));
            this.tabControlPanel3.Style.BorderSide = ((DevComponents.DotNetBar.eBorderSide)(((DevComponents.DotNetBar.eBorderSide.Left | DevComponents.DotNetBar.eBorderSide.Right)
                        | DevComponents.DotNetBar.eBorderSide.Bottom)));
            this.tabControlPanel3.Style.GradientAngle = 90;
            this.tabControlPanel3.TabIndex = 3;
            this.tabControlPanel3.TabItem = this.tabItem3;
            this.lvMusicList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader1,
            this.columnHeader2,
            this.columnHeader3});
            this.lvMusicList.ContextMenuStrip = this.contextMenuStrip1;
            this.lvMusicList.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lvMusicList.FullRowSelect = true;
            this.lvMusicList.GridLines = true;
            this.lvMusicList.Location = new System.Drawing.Point(1, 1);
            this.lvMusicList.Name = "lvMusicList";
            this.lvMusicList.Size = new System.Drawing.Size(296, 399);
            this.lvMusicList.TabIndex = 0;
            this.lvMusicList.UseCompatibleStateImageBehavior = false;
            this.lvMusicList.View = System.Windows.Forms.View.Details;
            this.lvMusicList.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lvMusicList_MouseDoubleClick);
            this.columnHeader1.Text = "";
            this.columnHeader1.Width = 30;
            this.columnHeader2.Text = "";
            this.columnHeader2.Width = 172;
            this.columnHeader3.Text = "";
            this.columnHeader3.Width = 75;
            this.tabItem3.AttachedControl = this.tabControlPanel3;
            this.tabItem3.Name = "tabItem3";
            this.tabItem3.Text = "本地歌曲";
            this.tabControlPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControlPanel1.Location = new System.Drawing.Point(0, 26);
            this.tabControlPanel1.Name = "tabControlPanel1";
            this.tabControlPanel1.Padding = new System.Windows.Forms.Padding(1);
            this.tabControlPanel1.Size = new System.Drawing.Size(298, 401);
            this.tabControlPanel1.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));
            this.tabControlPanel1.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));
            this.tabControlPanel1.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;
            this.tabControlPanel1.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(96)))), ((int)(((byte)(128)))), ((int)(((byte)(88)))));
            this.tabControlPanel1.Style.BorderSide = ((DevComponents.DotNetBar.eBorderSide)(((DevComponents.DotNetBar.eBorderSide.Left | DevComponents.DotNetBar.eBorderSide.Right)
                        | DevComponents.DotNetBar.eBorderSide.Bottom)));
            this.tabControlPanel1.Style.GradientAngle = 90;
            this.tabControlPanel1.TabIndex = 1;
            this.tabControlPanel1.TabItem = this.tabItem1;
            this.tabItem1.AttachedControl = this.tabControlPanel1;
            this.tabItem1.Name = "tabItem1";
            this.tabItem1.Text = "本地歌曲";
            this.tabControlPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControlPanel2.Location = new System.Drawing.Point(0, 26);
            this.tabControlPanel2.Name = "tabControlPanel2";
            this.tabControlPanel2.Padding = new System.Windows.Forms.Padding(1);
            this.tabControlPanel2.Size = new System.Drawing.Size(298, 401);
            this.tabControlPanel2.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));
            this.tabControlPanel2.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));
            this.tabControlPanel2.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;
            this.tabControlPanel2.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(96)))), ((int)(((byte)(128)))), ((int)(((byte)(88)))));
            this.tabControlPanel2.Style.BorderSide = ((DevComponents.DotNetBar.eBorderSide)(((DevComponents.DotNetBar.eBorderSide.Left | DevComponents.DotNetBar.eBorderSide.Right)
                        | DevComponents.DotNetBar.eBorderSide.Bottom)));
            this.tabControlPanel2.Style.GradientAngle = 90;
            this.tabControlPanel2.TabIndex = 2;
            this.tabControlPanel2.TabItem = this.tabItem2;
            this.tabItem2.AttachedControl = this.tabControlPanel2;
            this.tabItem2.Name = "tabItem2";
            this.tabItem2.Text = "网络歌曲";
            this.statusStrip1.BackColor = System.Drawing.Color.Transparent;
            this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripDropDownButton1,
            this.toolStripDropDownButton2});
            this.statusStrip1.Location = new System.Drawing.Point(0, 523);
            this.statusStrip1.Name = "statusStrip1";
            this.statusStrip1.Size = new System.Drawing.Size(298, 22);
            this.statusStrip1.TabIndex = 10;
            this.statusStrip1.Text = "statusStrip1";
            this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.tsmiOpenMusic,
            this.tsmiOpenFolderMusic,
            this.toolStripMenuItem1,
            this.tsmiOpenUrlMusic});
            this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image")));
            this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
            this.toolStripDropDownButton1.Size = new System.Drawing.Size(42, 20);
            this.toolStripDropDownButton1.Text = "文件";
            this.tsmiOpenMusic.Name = "tsmiOpenMusic";
            this.tsmiOpenMusic.Size = new System.Drawing.Size(154, 22);
            this.tsmiOpenMusic.Text = "添加本地歌曲";
            this.tsmiOpenMusic.Click += new System.EventHandler(this.tsmiOpenMusic_Click);
            this.tsmiOpenFolderMusic.Name = "tsmiOpenFolderMusic";
            this.tsmiOpenFolderMusic.Size = new System.Drawing.Size(154, 22);
            this.tsmiOpenFolderMusic.Text = "添加本地文件夹";
            this.tsmiOpenFolderMusic.Click += new System.EventHandler(this.tsmiOpenFolderMusic_Click);
            this.toolStripMenuItem1.Name = "toolStripMenuItem1";
            this.toolStripMenuItem1.Size = new System.Drawing.Size(151, 6);
            this.tsmiOpenUrlMusic.Name = "tsmiOpenUrlMusic";
            this.tsmiOpenUrlMusic.Size = new System.Drawing.Size(154, 22);
            this.tsmiOpenUrlMusic.Text = "添加网络歌曲";
            this.toolStripDropDownButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.toolStripDropDownButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton2.Image")));
            this.toolStripDropDownButton2.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripDropDownButton2.Name = "toolStripDropDownButton2";
            this.toolStripDropDownButton2.Size = new System.Drawing.Size(42, 20);
            this.toolStripDropDownButton2.Text = "系统";
            this.panel2.BackColor = System.Drawing.Color.Transparent;
            this.panel2.Controls.Add(this.btnPre);
            this.panel2.Controls.Add(this.btnLast);
            this.panel2.Controls.Add(this.btnPlayOrPause);
            this.panel2.Controls.Add(this.btnStop);
            this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel2.Location = new System.Drawing.Point(0, 66);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(298, 30);
            this.panel2.TabIndex = 8;
            this.btnPre.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
            this.btnPre.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
            this.btnPre.Enabled = false;
            this.btnPre.Location = new System.Drawing.Point(4, 3);
            this.btnPre.Name = "btnPre";
            this.btnPre.Size = new System.Drawing.Size(72, 23);
            this.btnPre.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;
            this.btnPre.TabIndex = 5;
            this.btnPre.Text = "上一曲";
            this.btnPre.Click += new System.EventHandler(this.btnPre_Click);
            this.btnLast.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
            this.btnLast.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
            this.btnLast.Enabled = false;
            this.btnLast.Location = new System.Drawing.Point(220, 3);
            this.btnLast.Name = "btnLast";
            this.btnLast.Size = new System.Drawing.Size(72, 23);
            this.btnLast.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;
            this.btnLast.TabIndex = 6;
            this.btnLast.Text = "下一曲";
            this.btnLast.Click += new System.EventHandler(this.btnLast_Click);
            this.btnPlayOrPause.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
            this.btnPlayOrPause.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
            this.btnPlayOrPause.Enabled = false;
            this.btnPlayOrPause.Location = new System.Drawing.Point(76, 3);
            this.btnPlayOrPause.Name = "btnPlayOrPause";
            this.btnPlayOrPause.Size = new System.Drawing.Size(72, 23);
            this.btnPlayOrPause.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;
            this.btnPlayOrPause.TabIndex = 4;
            this.btnPlayOrPause.Text = "开始播放";
            this.btnPlayOrPause.Click += new System.EventHandler(this.btnPlayOrPause_Click);
            this.btnStop.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
            this.btnStop.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
            this.btnStop.Enabled = false;
            this.btnStop.Location = new System.Drawing.Point(148, 3);
            this.btnStop.Name = "btnStop";
            this.btnStop.Size = new System.Drawing.Size(72, 23);
            this.btnStop.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;
            this.btnStop.TabIndex = 7;
            this.btnStop.Text = "停止播放";
            this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
            this.pnlTop.BackColor = System.Drawing.Color.Transparent;
            this.pnlTop.Controls.Add(this.lblMin);
            this.pnlTop.Controls.Add(this.lblExit);
            this.pnlTop.Controls.Add(this.progressBarX1);
            this.pnlTop.Controls.Add(this.chkAudioOnOff);
            this.pnlTop.Controls.Add(this.lblCurrentPosition);
            this.pnlTop.Controls.Add(this.lblDuration);
            this.pnlTop.Controls.Add(this.lblMusicName);
            this.pnlTop.Dock = System.Windows.Forms.DockStyle.Top;
            this.pnlTop.Location = new System.Drawing.Point(0, 0);
            this.pnlTop.Name = "pnlTop";
            this.pnlTop.Size = new System.Drawing.Size(298, 66);
            this.pnlTop.TabIndex = 3;
            this.pnlTop.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pnlTop_MouseMove);
            this.pnlTop.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pnlTop_MouseDown);
            this.lblMin.AutoSize = true;
            this.lblMin.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.lblMin.Location = new System.Drawing.Point(260, 2);
            this.lblMin.Name = "lblMin";
            this.lblMin.Size = new System.Drawing.Size(17, 16);
            this.lblMin.TabIndex = 10;
            this.lblMin.Text = "-";
            this.lblMin.Click += new System.EventHandler(this.lblMin_Click);
            this.lblExit.AutoSize = true;
            this.lblExit.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.lblExit.Location = new System.Drawing.Point(279, 3);
            this.lblExit.Name = "lblExit";
            this.lblExit.Size = new System.Drawing.Size(15, 14);
            this.lblExit.TabIndex = 9;
            this.lblExit.Text = "X";
            this.lblExit.Click += new System.EventHandler(this.lblExit_Click);
            this.progressBarX1.BackColor = System.Drawing.Color.Transparent;
            this.progressBarX1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.progressBarX1.Location = new System.Drawing.Point(0, 56);
            this.progressBarX1.Name = "progressBarX1";
            this.progressBarX1.Size = new System.Drawing.Size(298, 10);
            this.progressBarX1.TabIndex = 8;
            this.chkAudioOnOff.AutoSize = true;
            this.chkAudioOnOff.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.chkAudioOnOff.Location = new System.Drawing.Point(247, 20);
            this.chkAudioOnOff.Name = "chkAudioOnOff";
            this.chkAudioOnOff.Size = new System.Drawing.Size(45, 16);
            this.chkAudioOnOff.TabIndex = 1;
            this.chkAudioOnOff.Text = "静音";
            this.chkAudioOnOff.UseVisualStyleBackColor = true;
            this.chkAudioOnOff.CheckedChanged += new System.EventHandler(this.chkAudioOnOff_CheckedChanged);
            this.lblCurrentPosition.AutoSize = true;
            this.lblCurrentPosition.Location = new System.Drawing.Point(239, 39);
            this.lblCurrentPosition.Name = "lblCurrentPosition";
            this.lblCurrentPosition.Size = new System.Drawing.Size(53, 12);
            this.lblCurrentPosition.TabIndex = 3;
            this.lblCurrentPosition.Text = "00:00:00";
            this.lblDuration.AutoSize = true;
            this.lblDuration.Location = new System.Drawing.Point(4, 39);
            this.lblDuration.Name = "lblDuration";
            this.lblDuration.Size = new System.Drawing.Size(53, 12);
            this.lblDuration.TabIndex = 2;
            this.lblDuration.Text = "00:00:00";
            this.lblMusicName.AutoSize = true;
            this.lblMusicName.Location = new System.Drawing.Point(4, 20);
            this.lblMusicName.Name = "lblMusicName";
            this.lblMusicName.Size = new System.Drawing.Size(77, 12);
            this.lblMusicName.TabIndex = 1;
            this.lblMusicName.Text = "暂无音乐文件";
            this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.tsmenuDeleteChangeMusic,
            this.删除重复歌曲ToolStripMenuItem,
            this.toolStripMenuItem4,
            this.tsmenuClearList});
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(143, 76);
            this.tsmenuDeleteChangeMusic.Name = "tsmenuDeleteChangeMusic";
            this.tsmenuDeleteChangeMusic.Size = new System.Drawing.Size(142, 22);
            this.tsmenuDeleteChangeMusic.Text = "删除选中歌曲";
            this.tsmenuDeleteChangeMusic.Click += new System.EventHandler(this.tsmiDeleteChangeMusic_Click);
            this.删除重复歌曲ToolStripMenuItem.Name = "删除重复歌曲ToolStripMenuItem";
            this.删除重复歌曲ToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
            this.删除重复歌曲ToolStripMenuItem.Text = "删除重复歌曲";
            this.toolStripMenuItem4.Name = "toolStripMenuItem4";
            this.toolStripMenuItem4.Size = new System.Drawing.Size(139, 6);
            this.tsmenuClearList.Name = "tsmenuClearList";
            this.tsmenuClearList.Size = new System.Drawing.Size(142, 22);
            this.tsmenuClearList.Text = "清空歌曲列表";
            this.tsmenuClearList.Click += new System.EventHandler(this.tsmiClearList_Click);
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            this.notifyIcon1.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
            this.notifyIcon1.Text = "草莓¢音乐播放器";
            this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(298, 545);
            this.Controls.Add(this.ribbonClientPanel1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.MaximizeBox = false;
            this.Name = "Frm";
            this.Opacity = 0;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "草莓¢音乐播放器";
            this.Load += new System.EventHandler(this.Frm_Load);
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Frm_FormClosing);
            this.Resize += new System.EventHandler(this.Frm_Resize);
            this.ribbonClientPanel1.ResumeLayout(false);
            this.ribbonClientPanel1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tabControlPanel3.ResumeLayout(false);
            this.statusStrip1.ResumeLayout(false);
            this.statusStrip1.PerformLayout();
            this.panel2.ResumeLayout(false);
            this.pnlTop.ResumeLayout(false);
            this.pnlTop.PerformLayout();
            this.contextMenuStrip1.ResumeLayout(false);
            this.ResumeLayout(false);
        }
        private DevComponents.DotNetBar.Ribbon.RibbonClientPanel ribbonClientPanel1;
        private DevComponents.DotNetBar.ButtonX btnLast;
        private DevComponents.DotNetBar.ButtonX btnStop;
        private DevComponents.DotNetBar.ButtonX btnPlayOrPause;
        private DevComponents.DotNetBar.ButtonX btnPre;
        private System.Windows.Forms.Panel panel2;
        private DevComponents.DotNetBar.TabControl tabControl1;
        private DevComponents.DotNetBar.TabControlPanel tabControlPanel1;
        private DevComponents.DotNetBar.TabItem tabItem1;
        private DevComponents.DotNetBar.TabControlPanel tabControlPanel2;
        private DevComponents.DotNetBar.TabItem tabItem2;
        private System.Windows.Forms.StatusStrip statusStrip1;
        private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
        private System.Windows.Forms.ToolStripMenuItem tsmiOpenMusic;
        private System.Windows.Forms.ToolStripMenuItem tsmiOpenFolderMusic;
        private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
        private System.Windows.Forms.ToolStripMenuItem tsmiOpenUrlMusic;
        private System.Windows.Forms.Timer timer1;
        private DevComponents.DotNetBar.Controls.Slider slider1;
        private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton2;
        private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
        private System.Windows.Forms.ToolStripMenuItem tsmenuDeleteChangeMusic;
        private System.Windows.Forms.ToolStripMenuItem 删除重复歌曲ToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripMenuItem4;
        private System.Windows.Forms.ToolStripMenuItem tsmenuClearList;
        private System.Windows.Forms.NotifyIcon notifyIcon1;
        private System.Windows.Forms.Panel pnlTop;
        private DevComponents.DotNetBar.Controls.ProgressBarX progressBarX1;
        private System.Windows.Forms.CheckBox chkAudioOnOff;
        private System.Windows.Forms.Label lblCurrentPosition;
        private System.Windows.Forms.Label lblDuration;
        private System.Windows.Forms.Label lblMusicName;
        private DevComponents.DotNetBar.TabControlPanel tabControlPanel3;
        private System.Windows.Forms.ListView lvMusicList;
        private System.Windows.Forms.ColumnHeader columnHeader1;
        private System.Windows.Forms.ColumnHeader columnHeader2;
        private System.Windows.Forms.ColumnHeader columnHeader3;
        private DevComponents.DotNetBar.TabItem tabItem3;
        private System.Windows.Forms.Label lblExit;
        private System.Windows.Forms.Label lblMin;

    }
}

以下是功能模块代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Xml;
using System.Diagnostics;
using System.IO;

namespace CmTTPlayer
{
    public partial class Frm : Form
    {
        ///
        /// 强行释放内存资源
        ///
        ///
        ///
        ///
        ///
        [DllImport("kernel32", EntryPoint = "SetProcessWorkingSetSize", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        public static extern int SetProcessWorkingSetSize(int hProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);
        private Media media = new Media();
        //自增长序号
        private int number = 1;
        //当前播放曲目Index
        private int changeValue = 0;
        //当前播放曲目自增长序号
        private string changeItemText = "1";
        private Timer tmrShow = new Timer();
        Timer tmrClose;
        private int startX, StartY;
        public Frm()
        {
            InitializeComponent();
        }

        ///
        /// 初始化窗体数据
        ///
        ///
        ///
        private void Frm_Load(object sender, EventArgs e)
        {
            //获取进程的模块名称
            string mName = Process.GetCurrentProcess().MainModule.ModuleName;
            //返回没有扩展名的模块名称
            string pName = Path.GetFileNameWithoutExtension(mName);
            Process[] myProcess = Process.GetProcessesByName(pName);
            if (myProcess.Length > 1)
            {
                MessageBox.Show("当前程序已经运行", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Dispose();
                Application.ExitThread();
            }
            else
            {
                this.tmrShow.Tick += new EventHandler(this.tmrShow_Tick);
                this.tmrShow.Enabled = true;
            }     

            //设置图标
            this.Icon = Icon.ExtractAssociatedIcon("CmTTPlayer.ico");
            this.notifyIcon1.Icon = Icon.ExtractAssociatedIcon("CmTTPlayer.ico");
            media.SetAudioSource(Media.AudioSource.H);
            XmlDocument xmlDoc = new XmlDocument();
            //获取当前应用程序路径
            string path = Process.GetCurrentProcess().MainModule.FileName.Substring(0, Process.GetCurrentProcess().MainModule.FileName.LastIndexOf("//"));
            //加载Xml文件
            xmlDoc.Load(path + "//MusicFile.xml");
            XmlNode root = xmlDoc.SelectSingleNode("musiclist");//查找
            XmlNodeList xnl = root.ChildNodes;
            for (int i = 0; i < xnl.Count; i++)
            {
                ListViewItem item = new ListViewItem(number.ToString());
                item.SubItems.AddRange(new string[] { root.ChildNodes[i].Attributes["genre"].Value, root.ChildNodes[i].Attributes["lenght"].Value });
                item.Tag = root.ChildNodes[i].Attributes["filename"].Value;
                lvMusicList.Items.Add(item);
                number++;
                Application.DoEvents();
            }
            //在加载事件中执行以下
            SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle.ToInt32(), -1, -1);
        }

        ///
        /// 打开音乐文件
        ///
        ///
        ///
        private void tsmiOpenMusic_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect = true;
                ofd.Filter = "音乐文件|*.mp3;*.wma;*.wav";
                ofd.FileName = "打开文件";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    //获取当前应用程序路径
                    string path = Process.GetCurrentProcess().MainModule.FileName.Substring(0, Process.GetCurrentProcess().MainModule.FileName.LastIndexOf("//"));
                    //加载Xml文件
                    xmlDoc.Load(path + "//MusicFile.xml");
                    XmlNode root = xmlDoc.SelectSingleNode("musiclist");//查找
                    //遍历加载当前选中文件
                    foreach (string fileName in ofd.FileNames)
                    {
                        //打开音乐设备
                        media.OpenMusic(fileName, this.Handle);
                        //添加ListView项
                        ListViewItem item = new ListViewItem(number.ToString());
                        item.SubItems.AddRange(new string[] { Path.GetFileName(fileName),media.GetMusicLengthString() });
                        item.Tag = fileName;
                        lvMusicList.Items.Add(item);
                        XmlElement xe1 = xmlDoc.CreateElement("name");//创建一个节点
                        xe1.SetAttribute("genre", Path.GetFileName(fileName));//设置该节点genre属性
                        xe1.SetAttribute("filename", fileName);//设置该节点filename属性
                        xe1.SetAttribute("lenght", media.GetMusicLengthString());//设置该节点filename属性
                        number++;
                        root.AppendChild(xe1);//添加到节点中                        
                        //处理消息队列
                        Application.DoEvents();
                    }
                    xmlDoc.Save(path + "//MusicFile.xml");
                }
                if (lvMusicList.Items.Count > 0)
                    btnPlayOrPause.Enabled = true;
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle.ToInt32(), -1, -1);
        }

        ///
        /// 添加本地文件夹
        ///
        ///
        ///
        string fileInfo = string.Empty;
        private void tsmiOpenFolderMusic_Click(object sender, EventArgs e)
        {
            try
            {
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    DirectoryInfo dInfo = new DirectoryInfo(fbd.SelectedPath);
                    //遍历该文件夹
                    GetFolder(dInfo);
                }
                using (StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "//fileInfo.txt", false, Encoding.GetEncoding("gb2312")))
                {
                    sw.Write(fileInfo);
                    sw.Flush();
                }
                btnPlayOrPause.Enabled = true;
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //释放资源
            SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle.ToInt32(), -1, -1);
        }

        ///
        /// 递归文件夹
        ///
        ///
        private void GetFolder(DirectoryInfo dInfo)
        {
            //显示其中文件
            GetFile(dInfo);
            //遍历文件夹中的文件夹
            foreach (DirectoryInfo dir in dInfo.GetDirectories())
            {
                //递归遍历该文件夹
                GetFolder(dir);
            }
        }

        //遍历文件夹中的文件
        private void GetFile(DirectoryInfo dInfo)
        {
            XmlDocument xmlDoc = new XmlDocument();
            //获取当前应用程序路径
            string path = Process.GetCurrentProcess().MainModule.FileName.Substring(0, Process.GetCurrentProcess().MainModule.FileName.LastIndexOf("//"));
            //加载Xml文件
            xmlDoc.Load(path + "//MusicFile.xml");
            XmlNode root = xmlDoc.SelectSingleNode("musiclist");//查找
            foreach (FileInfo fileName in dInfo.GetFiles())
            {
                //获取文件扩展名
                string extension = Path.GetFileName(fileName.FullName).Substring(Path.GetFileName(fileName.FullName).IndexOf("."));
                //判断是否为音乐文件
                if (extension.ToLower().Equals(".mp3") || extension.ToLower().Equals(".wma") || extension.ToLower().Equals(".wav"))
                {
                    media.OpenMusic(fileName.FullName, this.Handle);
                    string[] str = new string[lvMusicList.Columns.Count];
                    ListViewItem item = new ListViewItem(number.ToString());
                    item.SubItems.AddRange(new string[] { Path.GetFileName(fileName.FullName), media.GetMusicLengthString() });
                    item.Tag = fileName.FullName;
                    lvMusicList.Items.Add(item);
                    XmlElement xe1 = xmlDoc.CreateElement("name");//创建一个节点
                    xe1.SetAttribute("genre", Path.GetFileName(fileName.FullName));//设置该节点genre属性
                    xe1.SetAttribute("filename", fileName.FullName);//设置该节点filename属性
                    xe1.SetAttribute("lenght", media.GetMusicLengthString());//设置该节点lenght属性
                    number++;
                    root.AppendChild(xe1);//添加到节点中      
                    number++;
                }
                Application.DoEvents();
            }
            xmlDoc.Save(path + "//MusicFile.xml");
        }

        ///
        /// 上一曲
        ///
        ///
        ///
        private void btnPre_Click(object sender, EventArgs e)
        {
            try
            {
                //还原当前曲目播放状态
                lvMusicList.Items[changeValue].SubItems[0].Text = changeItemText;
                if (changeValue <= 0)
                    changeValue = lvMusicList.Items.Count - 1;
                else
                    changeValue--;
                //初始化播放曲目
                GetDownOrUp(sender, e);
                //按钮状态
                GetPlayButton();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        ///
        /// 下一曲
        ///
        ///
        ///
        private void btnLast_Click(object sender, EventArgs e)
        {
            try
            {
                //还原当前曲目播放状态
                lvMusicList.Items[changeValue].SubItems[0].Text = changeItemText;
                if (changeValue >= lvMusicList.Items.Count - 1)
                    changeValue = 0;
                else
                    changeValue++;
                //初始化播放曲目
                GetDownOrUp(sender, e);
                //按钮状态
                GetPlayButton();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        ///
        /// 播放暂停
        ///
        ///
        ///
        private void btnPlayOrPause_Click(object sender, EventArgs e)
        {
            try
            {
                if (lvMusicList.SelectedItems.Count > 0)
                {
                    if (btnPlayOrPause.Text.Equals("开始播放"))
                    {
                        media.PlayMusic();
                        //设置当前音量
                        slider1_Scroll(sender, e);
                        GetPlayButton();
                    }
                    else
                    {
                        GetPauseButton();
                        media.PauseMusic();
                    }
                }
                else
                    MessageBox.Show("请选中要播放的文件", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        ///
        /// 停止播放
        ///
        ///
        ///
        private void btnStop_Click(object sender, EventArgs e)
        {
            try
            {
                //停止播放
                media.CloseMusic();
                //设置控件状态
                GetStopButton();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        ///
        /// 设置进度
        ///
        ///
        ///
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                //设置音乐当前时间
                progressBarX1.Value = media.GetMusicPos();
                //设置音乐的当前进度
                lblDuration.Text = media.GetMusicPosString();
                progressBarX1.Text = (progressBarX1.Value / progressBarX1.Maximum).ToString();
                //判断是否已经播放完成
                if (progressBarX1.Value == progressBarX1.Maximum)
                {
                    //还原播放标识编号
                    lvMusicList.Items[changeValue].SubItems[0].Text = changeItemText;
                    //播放下一曲
                    if (changeValue >= lvMusicList.Items.Count - 1)
                        changeValue = 0;
                    else
                        changeValue++;
                    media.PlayMusic();
                    GetDownOrUp(sender, e);
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle.ToInt32(), -1, -1);
        }

        ///
        /// 设置音量
        ///
        ///
        ///
        private void slider1_Scroll(object sender, EventArgs e)
        {
            media.SetValume(slider1.Value);
            //lblSoundValue.Text = "音量:" + slider1.Value.ToString() + "Kbps";
        }

        ///
        /// 设置声道
        ///
        ///
        ///
        private void rdo_CheckedChanged(object sender, EventArgs e)
        {
            //if (rdoCenter.Checked == true)
            //    media.SetAudioSource(Media.AudioSource.H);
            //else if (rdoLeft.Checked == true)
            //    media.SetAudioSource(Media.AudioSource.L);
            //else if (rdoRight.Checked == true)
            //    media.SetAudioSource(Media.AudioSource.R);
        }

        ///
        /// 设置静音
        ///
        ///
        ///
        private void chkAudioOnOff_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAudioOnOff.Checked)
                media.SetAudioOnOff(true);
            else
                media.SetAudioOnOff(false);
        }

        ///
        /// 双击音乐文件列表播放
        ///
        ///
        ///
        private void lvMusicList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                lvMusicList.Items[changeValue].SubItems[0].Text = changeItemText;
                changeValue = lvMusicList.SelectedIndices[0];
                lblMusicName.Text = lvMusicList.SelectedItems[0].SubItems[2].Text;
                GetDownOrUp(sender, e);
                GetPlayButton();
                media.PlayMusic();
                //设置声音
                media.SetValume(slider1.Value);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        ///
        /// 删除选中歌曲
        ///
        ///
        ///
        private void tsmiDeleteChangeMusic_Click(object sender, EventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();
            //获取当前应用程序路径
            string path = Process.GetCurrentProcess().MainModule.FileName.Substring(0, Process.GetCurrentProcess().MainModule.FileName.LastIndexOf("//"));
            //加载Xml文件
            xmlDoc.Load(path + "//MusicFile.xml");
            XmlNodeList root = xmlDoc.SelectSingleNode("musiclist").ChildNodes;//查找
            foreach (XmlNode xn in root)
            {
                XmlElement xe = (XmlElement)xn;
                if (xe.GetAttribute("genre") == lvMusicList.SelectedItems[0].SubItems[0].Name)
                {
                    xe.RemoveAll();//删除该节点的全部内容
                }
            }
            xmlDoc.Save(path + "//MusicFile.xml");
            //清空列表
            lvMusicList.Items.Clear();
        }

        ///
        /// 清空当前列表
        ///
        ///
        ///
        private void tsmiClearList_Click(object sender, EventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();
            //获取当前应用程序路径
            string path = Process.GetCurrentProcess().MainModule.FileName.Substring(0, Process.GetCurrentProcess().MainModule.FileName.LastIndexOf("//"));
            //加载Xml文件
            xmlDoc.Load(path + "//MusicFile.xml");
            XmlNode root = xmlDoc.SelectSingleNode("musiclist");//查找
            root.RemoveAll();
            xmlDoc.Save(path + "//MusicFile.xml");
            //清空列表
            lvMusicList.Items.Clear();
        }

        ///
        /// 初始化播放曲目
        ///
        private void GetDownOrUp(object sender, EventArgs e)
        {
            //将当前播放曲目序号保存
            changeItemText = lvMusicList.Items[changeValue].SubItems[0].Text;
            //将当前播放曲目标识为正在播放
            lvMusicList.Items[changeValue].SubItems[0].Text = "★";
            //设置当前播放曲目地址
            media.OpenMusic(lvMusicList.Items[changeValue].Tag.ToString(), this.Handle);
            //设置曲目总长度
            lblCurrentPosition.Text = media.GetMusicLengthString();
            //开始播放
            media.PlayMusic();
            //设置进度条长度
            progressBarX1.Maximum = media.GetMusicLength();
            //设置曲目标题
            lblMusicName.Text = lvMusicList.Items[changeValue].SubItems[1].Text;
            //设置当前音量
            slider1_Scroll(sender, e);
        }

        ///
        /// 播放状态下控件
        ///
        private void GetPlayButton()
        {
            btnPlayOrPause.Text = "暂停播放";
            btnPre.Enabled = true;
            btnLast.Enabled = true;
            btnPlayOrPause.Enabled = true;
            btnStop.Enabled = true;
            timer1.Enabled = true;
        }

        ///
        /// 暂停状态下的控件
        ///
        private void GetPauseButton()
        {
            btnPlayOrPause.Text = "开始播放";
            timer1.Enabled = false;
            btnStop.Enabled = false;
            btnPlayOrPause.Enabled = true;
        }

        ///
        /// 停止状态下的控件
        ///
        private void GetStopButton()
        {
            timer1.Enabled = false;
            btnStop.Enabled = false;
            btnPlayOrPause.Enabled = false;
            btnLast.Enabled = false;
            btnPre.Enabled = false;
            //将当前播放曲目标识为正在播放
            lvMusicList.Items[changeValue].SubItems[0].Text = changeItemText;
            progressBarX1.Value = 0;
            lblDuration.Text = "00:00:00";
            lblCurrentPosition.Text = "00:00:00";
            lblMusicName.Text = "暂无音乐文件";
        }

        ///
        /// 淡出加载主窗体
        ///
        ///
        ///
        private void tmrShow_Tick(object sender, EventArgs e)
        {
            this.Opacity += 0.1;
            if (this.Opacity >= 1)
            {
                this.tmrShow.Dispose();
            }
        }

        ///
        /// 窗体状态改变时
        ///
        ///
        ///
        public void Frm_Resize(object sender, EventArgs e)
        {
            //最小化隐藏
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.Visible = false;
                notifyIcon1.Visible = true;
            }
            else
            {
                this.Visible = true;
                notifyIcon1.Visible = false;
            }
        }

        ///
        /// 双击状态栏图标还原窗体
        ///
        ///
        ///
        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            this.Visible = true;
            this.WindowState = FormWindowState.Normal;
        }

        ///
        /// 退出应用程序
        ///
        ///
        ///
        private void Frm_FormClosing(object sender, FormClosingEventArgs e)
        {
            ExitForm exitForm = new ExitForm();
            exitForm.ShowDialog(this);
            e.Cancel = true; ;
        }

        ///
        /// 鼠标按下记录当前位置
        ///
        ///
        ///
        private void pnlTop_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                startX = e.X;
                StartY = e.Y;
            }
        }

        ///
        /// 鼠标移动时改变窗体位置
        ///
        ///
        ///
        private void pnlTop_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Left += e.X - startX;
                this.Top += e.Y - StartY;
            }
        }

        ///
        /// 关闭窗体
        ///
        ///
        ///
        private void lblExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

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

你可能感兴趣的:(C# WinForm 音乐播放器源码)