嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 3 元微信扫码支付:3 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
提供本地音乐(mp3)格式的播放,以及查看歌词等功能(需将歌词文件放在exe文件的同级lyric目录下,且歌词文件名必须与歌词文件名相同,播放器会自动加载)
、 /// <summary>
/// 添加歌曲
/// </summary>
private void OpenMusic()
{
open.Filter = "音频文件(*.mp3)|*.mp3"; //文件过滤
if (open.ShowDialog() == DialogResult.OK)
{
if (CheckSelect())
{
file = new FileStream(@"MusicList.txt", FileMode.Append, FileAccess.Write);
sw = new StreamWriter(file);
lbMusicList.Items.Add(MusicName(open.FileName)); //将音频文件添加到列表框内
sw.WriteLine(open.FileName); //写入播放列表文件
//关闭两个对象
sw.Close();
file.Close();
if (Convert.ToInt32(wmpPlayer.playState) != 3) //正在播放音乐
{
wmpPlayer.URL = open.FileName; //添加到播放器
lbMusicList.SelectedIndex = lbMusicList.Items.Count - 1; //选择添加的歌曲文件
}
GetMusicName();
}
else
{
MessageBox.Show("列表中已经存在该文件!","提示",MessageBoxButtons.OK);
}
}
}
/// <summary>
/// 获得歌曲名
/// </summary>
private string MusicName(string path)
{
string name= path.Substring(path.LastIndexOf(@"\") 1);
string[] names = name.Split('.');
return names[0];
}
/// <summary>
/// 获得播放路径
/// </summary>
/// <param name="name"></param>
private string MusicPath(string name)
{
string[] musicList = File.ReadAllLines(@"MusicList.txt");
int i=0;
for (; i < musicList.Length; i )
{
if (musicList[i].IndexOf(name) != -1)
{
break;
}
}
return musicList[i];
}
/// <summary>
/// 检查选择的路径
/// </summary>
private bool CheckSelect()
{
bool flag = true;
if (File.Exists(@"MusicList.txt")) //判断列表文件是否存在
{
string[] musicList = File.ReadAllLines(@"MusicList.txt");
for (int i = 0; i < musicList.Length; i ) //判断选择的路径是否存在
{
if (musicList[i].Equals(open.FileName))
{
flag = false;
}
}
}
return flag;
}
/// <summary>
/// 加载时检查选择的路径
/// </summary>
private bool CheckSelectLoad()
{
bool flag = true;
if (File.Exists(@"MusicList.txt")) //判断列表文件是否存在
{
string[] musicList = File.ReadAllLines(@"MusicList.txt");
for (int i = 0; i < musicList.Length; i ) //判断选择的路径是否存在
{
if (musicList[i].Equals(name))
{
flag = false;
}
}
}
return flag;
}
/// <summary>
/// 设置播放名
/// </summary>
private void GetMusicName()
{
lblZhuangTai.Text = lbMusicList.SelectedItem.ToString();
}
/// <summary>
/// 双击播放列表项
/// </summary>
private void lbMusicList_DoubleClick(object sender, EventArgs e)
{
if (lbMusicList.Items.Count != 0)
{
if (lbMusicList.SelectedIndex != -1)
{
wmpPlayer.URL = MusicPath(lbMusicList.SelectedItem.ToString());
GetMusicName();
}
}
}