www.pudn.com > seamp3.rar > Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Sunisoft.IrisSkin;
namespace seamp3
{
public partial class Form1 : Form
{
private Player MyPlayer;
public Form1()
{
InitializeComponent();
//axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer();
MyPlayer = new Player(axWindowsMediaPlayer1);
this.mLoad();
}
private void Form1_Load(object sender, EventArgs e)
{
//this.axMMControl1.FileName = @"E:\Borland\JBuilder2006\j2mewtk2.2\wtklib\devices\Share\mid_info.wav";
//this.axMMControl1.PlayEnabled = true;
//更换皮肤
// Sunisoft.IrisSkin.SkinEngine MyIrisSkin = new Sunisoft.IrisSkin.SkinEngine ();
// MyIrisSkin.SkinAllForm =
}
private void showfiles(string path, ListBox listBox1)
{
DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileInfo f in dir.GetFiles("*.mp3"))
{
MyPlayer.AddFile(f.FullName);
}
foreach (DirectoryInfo f in dir.GetDirectories())
{
showfiles(f.FullName, listBox1);
}
}
private void mLoad()
{
listBox1.Items.Clear();
for (int i = 1; i <= MyPlayer.NumOfMusic; i++)
{
string STRFILE = Convert.ToString(i);
for (int j = 1; j <= 5 - STRFILE.Length; j++) STRFILE += ' ';
FileInfo f = new FileInfo(MyPlayer.PlayList(i));
STRFILE += f.Name;
this.listBox1.Items.Add(STRFILE);
}
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.Visible = true;
this.WindowState = System.Windows.Forms.FormWindowState.Normal;
this.notifyIcon1.Visible = false;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.notifyIcon1.Visible = true;
this.Visible = false;
}
}
private void 将文件添加到列表ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Title = "添加文件";
openDlg.InitialDirectory = "e:\\";
openDlg.Filter = "音频文件(*.mp3,*.wma,*.wav,*.ra,*.rm)|*.mp3;*.wma;*.wav;*.ra;*.rm|视频文件(*.asf,*.wmv,*.mpeg,*.mpg,*.rmvb)|*.asf;*.wmv;*.mpeg;*.rmvb";
if (openDlg.ShowDialog() == DialogResult.OK)
{
//string path = this.openFileDialog1.FileName;
string path = openDlg.FileName;
FileInfo f = new FileInfo(path);
MyPlayer.AddFile(f.FullName);
mLoad();
}
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
string path = this.folderBrowserDialog1.SelectedPath;
showfiles(path, listBox1);
mLoad();
}
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
if (listBox1.SelectedIndex >= 0)
MyPlayer.play(listBox1.SelectedIndex+1);
}
private void 下一首歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MyPlayer.CurrentPlay > 0)
{
int play = MyPlayer.CurrentPlay + 1;
if (play > MyPlayer.NumOfMusic) play = 1;
MyPlayer.play(play);
listBox1.SelectedIndex = play - 1;
}
}
private void 删除选定歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex >= 0)
{
MyPlayer.DelFile(listBox1.SelectedIndex + 1);
listBox1.Items.Clear();
mLoad();
}
}
private void 清除所有歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
MyPlayer.NumOfMusic = 0;
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
MyPlayer.save();
Application.Exit();
}
private void 上一首歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MyPlayer.CurrentPlay > 0)
{
int play = MyPlayer.CurrentPlay - 1;
if (play == 0) play = MyPlayer.NumOfMusic;
MyPlayer.play(play);
listBox1.SelectedIndex = play - 1;
}
}
private void 顺序播放ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.顺序播放ToolStripMenuItem.Checked = true;
this.随机播放ToolStripMenuItem.Checked = false;
//this.重复播放ToolStripMenuItem.Checked = false;
this.重复播放此歌曲ToolStripMenuItem.Checked = false;
this.重复播放所有歌曲ToolStripMenuItem.Checked = false;
}
private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (MyPlayer.playstate == WMPLib.WMPPlayState.wmppsMediaEnded)
{
timer1.Start();
}
}
private void 重复播放ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void 重复播放所有歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.顺序播放ToolStripMenuItem.Checked = false;
this.随机播放ToolStripMenuItem.Checked = false;
//this.重复播放ToolStripMenuItem.Checked = false;
this.重复播放此歌曲ToolStripMenuItem.Checked = false;
this.重复播放所有歌曲ToolStripMenuItem.Checked = true;
}
private void 重复播放此歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.顺序播放ToolStripMenuItem.Checked = false;
this.随机播放ToolStripMenuItem.Checked = false;
//this.重复播放ToolStripMenuItem.Checked = false;
this.重复播放此歌曲ToolStripMenuItem.Checked = true;
this.重复播放所有歌曲ToolStripMenuItem.Checked = false;
}
private void 随机播放ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.顺序播放ToolStripMenuItem.Checked =false;
this.随机播放ToolStripMenuItem.Checked = true;
//this.重复播放ToolStripMenuItem.Checked = false;
this.重复播放此歌曲ToolStripMenuItem.Checked = false;
this.重复播放所有歌曲ToolStripMenuItem.Checked = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Stop();
int selectnum = 0;
if (this.顺序播放ToolStripMenuItem.Checked) selectnum = MyPlayer.NextPlay(0);
else if (this.重复播放所有歌曲ToolStripMenuItem.Checked) selectnum = MyPlayer.NextPlay(1);
else if (this.重复播放此歌曲ToolStripMenuItem.Checked) selectnum = MyPlayer.NextPlay(2);
else if (this.顺序播放ToolStripMenuItem.Checked) selectnum = MyPlayer.NextPlay(3);
if (selectnum != 0)
{
listBox1.SelectedIndex = selectnum - 1;
MyPlayer.play(selectnum);
}
}
private void listBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
if (listBox1.SelectedIndex >= 0)
{
int tmp = listBox1.SelectedIndex;
MyPlayer.DelFile(listBox1.SelectedIndex + 1);
mLoad();
if (tmp > MyPlayer.NumOfMusic - 1) tmp = -1;
listBox1.SelectedIndex = tmp;
}
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.All;
else
e.Effect = DragDropEffects.None;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
//if (e.Data.GetDataPresent(DataFormats.FileDrop))
//{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop,false);
foreach (string file in files)
{
MyPlayer.AddFile(file);
}
mLoad();
//}
}
private void 控制ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void 关于seamp3ToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show(" 关于seamp3 \n\n 声明:本软件仅供学习参考 \n 版权:CUC--计算机软件学院\n 2006");
}
}
}