上一个版本的 mp3 player 时间仓促,代码中存在不少错误,功能也不完善。这一个多月一直用自己做的 seaPlayer ( 给它暂时取个名字 ) 听歌 , 改了不少漏洞,还完善了一些功能。这些功能有 :
1. 最小化时隐藏界面,只在显示在状态栏里显示图标。
2. 退出程序时能将播放列表中的歌曲保存起来,以便下次启动播放器时能装载列表。
3. 增加了文件拖放功能,把想听的歌曲直接拖到窗口就可以添加进列表。
4. 增加了键盘 del 键对删除歌曲的控制,可以方便删除不想听的歌曲。
下面是全部的代码:
** seaPlayer.cs:
**
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace seaPlayer
{
///
1<summary>
2
3/// Form1 的摘要说明。
4
5/// </summary>
public class seaPlayer : System.Windows.Forms.Form
{
private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.MenuItem menuItem15;
private System.Windows.Forms.MenuItem menuItem16;
private System.Windows.Forms.MenuItem menuItem17;
private System.Windows.Forms.MenuItem menuItem18;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.Timer timer1;
private Player MyPlayer;
public seaPlayer()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this .notifyIcon1.Icon = new System.Drawing.Icon("dog.ico");
this .notifyIcon1.Visible = false ;
MyPlayer = new Player(axWindowsMediaPlayer1);
this .Load();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
1<summary>
2
3/// 清理所有正在使用的资源。
4
5/// </summary>
protected override void Dispose( bool disposing )
{
MyPlayer.save();
if ( disposing )
{
if (components != null )
{
components.Dispose();
}
}
base .Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
1<summary>
2
3/// 设计器支持所需的方法 \- 不要使用代码编辑器修改
4
5/// 此方法的内容。
6
7/// </summary>
private void InitializeComponent()
{
this .components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager( typeof (seaPlayer));
this .axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer();
this .mainMenu1 = new System.Windows.Forms.MainMenu();
this .menuItem1 = new System.Windows.Forms.MenuItem();
this .menuItem2 = new System.Windows.Forms.MenuItem();
this .menuItem3 = new System.Windows.Forms.MenuItem();
this .menuItem5 = new System.Windows.Forms.MenuItem();
this .menuItem4 = new System.Windows.Forms.MenuItem();
this .menuItem7 = new System.Windows.Forms.MenuItem();
this .menuItem8 = new System.Windows.Forms.MenuItem();
this .menuItem9 = new System.Windows.Forms.MenuItem();
this .menuItem6 = new System.Windows.Forms.MenuItem();
this .menuItem10 = new System.Windows.Forms.MenuItem();
this .menuItem11 = new System.Windows.Forms.MenuItem();
this .menuItem12 = new System.Windows.Forms.MenuItem();
this .menuItem13 = new System.Windows.Forms.MenuItem();
this .menuItem14 = new System.Windows.Forms.MenuItem();
this .menuItem15 = new System.Windows.Forms.MenuItem();
this .menuItem16 = new System.Windows.Forms.MenuItem();
this .menuItem17 = new System.Windows.Forms.MenuItem();
this .menuItem18 = new System.Windows.Forms.MenuItem();
this .folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this .listBox1 = new System.Windows.Forms.ListBox();
this .notifyIcon1 = new System.Windows.Forms.NotifyIcon( this .components);
this .openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this .timer1 = new System.Windows.Forms.Timer( this .components);
((System.ComponentModel.ISupportInitialize)( this .axWindowsMediaPlayer1)).BeginInit();
this .SuspendLayout();
//
// axWindowsMediaPlayer1
//
this .axWindowsMediaPlayer1.Dock = System.Windows.Forms.DockStyle.Bottom;
this .axWindowsMediaPlayer1.Enabled = true ;
this .axWindowsMediaPlayer1.Location = new System.Drawing.Point(0, 256);
this .axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";
this .axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState")));
this .axWindowsMediaPlayer1.Size = new System.Drawing.Size(216, 45);
this .axWindowsMediaPlayer1.TabIndex = 0;
this .axWindowsMediaPlayer1.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler( this .axWindowsMediaPlayer1_PlayStateChange);
//
// mainMenu1
//
this .mainMenu1.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] {
this .menuItem1,
this .menuItem6,
<span lang="EN-US" style="FONT-