虽然是很简单,但毕竟也是我的第一个windows应用程序作品,大家不要见怪咯,希望路过的朋友们,给点意见,很想跟你们多多交流··
namespace MP3
{
public partial class Form1 : Form
{
private string[] playList = new string[10000];
private int num;
public void AddFile(string path)
{
if (num < 10000)
{
num++;
playList[num] = path;
}
}
public void DelFile(int selectNum)
{
for (int i = selectNum; i <= num - 1; i++)
{
playList[i] = playList[i + 1];
}
num--;
}
private void AddFiles(string path, ListBox listBox1)
{
DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileInfo f in dir.GetFiles("*.mp3"))
{
AddFile(f.FullName);
string strTmp = Convert.ToString(num);
for (int i = 1; i <= 5 - strTmp.Length; i++)
{
strTmp +=' ';
}
strTmp +="-"+f.Name ;
this .listBox1 .Items.Add (strTmp );
}
foreach(DirectoryInfo f in dir .GetDirectories ())
{
AddFiles (f.FullName ,listBox1 );
}
}
public void PlaySong(int selectNum)
{
MediaPlayer1.URL= playList[selectNum];
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1 .Items.CopyTo (playList ,0);
num = 0;
}
private void button1_Click(object sender, EventArgs e)
{
folderBrowserDialog1.SelectedPath = "d://";
folderBrowserDialog1.ShowNewFolderButton = true ;
folderBrowserDialog1.Description = "请选择音乐文件目录:";
folderBrowserDialog1.ShowDialog();
AddFiles(folderBrowserDialog1.SelectedPath,listBox1 );
}
private void button2_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex >= 0)
{
DelFile(listBox1.SelectedIndex +1);
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
}
}
private void button3_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "*.mp3|*.mp3";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
string path = this.openFileDialog1.FileName;
FileInfo f = new FileInfo(path);
AddFile(f.FullName);
string strTmp = Convert.ToString(num);
for (int i = 1; i <= 5 - strTmp.Length; i++)
{
strTmp +=' ';
}
strTmp +="-"+f.Name ;
this .listBox1 .Items.Add(strTmp );
}
}
private void button5_Click(object sender, EventArgs e)
{
MediaPlayer1.URL = "";
}
private void button4_Click(object sender, EventArgs e)
{
int SelectOne;
if (listBox1.SelectedIndex < 0)
SelectOne = 1;
else
SelectOne = listBox1.SelectedIndex + 1;
if (listBox1.Items.Count < 0)
listBox1.SelectedIndex = 0;
PlaySong(SelectOne);
}
图:

本文介绍了一个简单的Windows平台MP3播放器应用开发过程。该应用可以添加、删除MP3文件,并实现基本的播放功能。文章详细展示了如何通过C#语言进行文件管理和播放控制。
2488

被折叠的 条评论
为什么被折叠?



