2024年3月19日发(作者:)
using System;
using c;
using entModel;
using ;
using g;
using ;
using ;
using ;
using ;
using ;
using ;
using ing;
namespace MyMusicPlays
{
public partial class Form1 : Form
{
Thread t, d;
Dictionary
Dictionary
MusicInfo musicInfo = null;
int subId = 0;
DateTime openTheMusic;
public Form1()
{
InitializeComponent();
}
public static string SaveMusic = @"D:";
private void button1_Click(object sender, EventArgs
e)
{
}
//播放、暂停按钮
private void button1_Click_1(object sender, EventArgs
e)
{
if (ate==
ndefined ||
ate== aused
|| ate==
topped)
{
();
= "暂停(&P)";
();
}
else
{
();
= "播放(&P)";
();
}
}
//停止按钮
private void button3_Click(object sender, EventArgs
e)
{
();
= "播放(&P)";
= 0;
();
}
//上传本地音乐
private void linkLabel1_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
= "mp3音乐音频(*.mp3)|*.mp3|wma音乐音频
(*.wma)|*.wma";
DialogResult dr = alog();
if (dr == )
{
musicInfo = new MusicInfo();
//获取最后一个的位置
int lastIndex = dexOf(@"");
//获取文件名字
string musicName =
ing(lastIndex + 1);
d = == 0 ? 1 :
+ 1;
ame = musicName;
rl = me;
ime = "00:00";
fillListView(musicInfo);
(d, musicInfo);
}
}
//填充表格的方法
private void fillListView(MusicInfo mi)
{
ListViewItem item = new
ListViewItem(ng());
ge(new string[]
{ame,ime });
(item);
}
private void lsvItems_SelectedIndexChanged(object
sender, EventArgs e)
{
}
//动态显示时间
private void runTime()
{
while (true)
{
try
{
TimeSpan span = -
openTheMusic;
string musicTime =
ng().Substring(3,5);
(new
MethodInvoker(delegate
{ = "当前进度:" +
musicTime; }));
}
catch(Exception)
{
return;
}
(1000);
}
}
///
/// 通过线程去播放音乐
///
private void run()
{
();
//控件事件委托(在线程里面失效)
try
{
(new MethodInvoker(delegate
{ subId =
(edItems[0].SubItems[0].Text); })
);
}
catch (Exception )
{
return;
}
string url = dicMusic[subId].MusicUrl;
= url;
();
}
//保存音乐--序列化文件
private void linkLabel2_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
FileStream fs = new FileStream(SaveMusic,
);
BinaryFormatter bf = new BinaryFormatter();
ize(fs, dicMusic);
();
("音乐文件保存成功!","提示
",,ation);
}
//窗体加载时显示出保存文件信息
private void Form1_Load(object sender, EventArgs e)
{
le = "";
= ;
= "";
= "";
//读取
loading(readMessage());
}
//加载时候fill表格
private void loading(Dictionary
dicMusic)
{
foreach (MusicInfo mi in )
{
ListViewItem item = new
ListViewItem(ng());
ge(new string[]
{ ame, ime });
(item);
}
}
//读取本地信息
private Dictionary
{
try
{
FileStream fs = new FileStream(SaveMusic,
);
BinaryFormatter bf = new BinaryFormatter();
dicMusic = (Dictionary MusicInfo>)alize(fs); (); } catch (Exception) { FileStream fs = new FileStream(SaveMusic, ); (); } return dicMusic; } private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { showTheMusicTimes(); } /// /// 获取歌曲长度 /// private void showTheMusicTimes() { //检查状态~ if (ate == topped || ate == ndefined || subId == 0) { return; } if ( <= 0) return; string thisTime = onString; dicMusic[subId].MusicTime = thisTime; edItems[0].SubItems[2].Text = thisTime; } private void button1_Click_2(object sender, EventArgs e) { DateTime times = Time(onStrin g); int min = ; int sco = ; int sum = min * 60 + sco; (ng()); } private void timer1_Tick(object sender, EventArgs e) { if ( < m) { ++; } } //窗体关闭~线程终止 private void Form1_FormClosing(object sender, FormClosingEventArgs e) { try { (); } catch (Exception) { return; } } //增加音量图片按钮 private void pictureBox2_Click(object sender, EventArgs e) { if ( <= 95) { += 5; = ; } } /// /// 滚动时候改变音量大小 /// /// /// private void tbMessage_Scroll(object sender, EventArgs e) { = ; } //减少音量图片按钮 private void pictureBox1_Click(object sender, EventArgs e) { if ( >= 5) { += -5; = ; } } private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Form2 f2 = new Form2(); (); } private void lsvItems_DoubleClick(object sender, EventArgs e) { if ( <= 0) return; d = true; t = new Thread(new ThreadStart(run)); (); = 0; //进度条工作..获取预播放曲目的时长 string strTimes = edItems[0].SubItems[2].Text; if (strTimes == "00:00") { showTheMusicTimes(); strTimes = edItems[0].SubItems[2].Text; } DateTime times = Time(strTimes); int min = ; int sco = ; m = (min * 60 + sco); (); = "曲目时长:" + strTimes; openTheMusic = ; d = new Thread(new ThreadStart(runTime)); (); = "暂停(&P)"; } private void 播放ToolStripMenuItem_Click(object sender, EventArgs e) { lsvItems_DoubleClick(sender, e); } private void 移入播放单ToolStripMenuItem_Click(object sender, EventArgs e) { if ( <= 0) return; } } }


发布评论