| |
C#中利用mediaplayer打造mp3播放器 |
出处:网易学院 |
|
| [ 2005-09-06 10:02:36
] |
作者:unknow
|
责任编辑:moningfeng |
分功能列出其他主要代码
添加单个歌曲
if(this.openFileDialog1.ShowDialog() == DialogResult.OK) { string path = this.openFileDialog1.FileName; FileInfo f = new FileInfo(path); MyPlayer.AddFile(f.FullName); string STRFILE = Convert.ToString(MyPlayer.NumOfMusic); for(int i = 1;i<=5-STRFILE.Length;i++)STRFILE+=’ ’; STRFILE += f.Name; this.listBox1.Items.Add(STRFILE); } 添加一个文件夹及其所有子文件夹的歌曲
利用递归函数showfiles实现所有层歌曲都添加到歌曲列表中。
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); } 删除和清空直接调用类Player中的AddFile和DelFile函数
|