目前网络上很多C#做的音乐播放器,但是功能不尽人意。本人通过网上的播放器源码结合自身的知识做出一个比较好的播放器,供大家交流。如图:
以下是播放器界面代码,新建一个项目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.lvMusicLis