110,537
社区成员
发帖
与我相关
我的任务
分享
//添加音乐
private void btn_Add_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.AddExtension = true;
ofd.CheckFileExists = true;
ofd.CheckPathExists = true;
ofd.Filter = "所有影音文件(*.mp3;*.wma;*.wav;*.avi;*.wmv;*.mpeg;*.mpg;*.dat;*.rm;*.rmvb)|*.mp3;*.dat;*.wma;*.wav;*.avi;*.wmv;*.mpeg;*.mpg;*.rm;*.rmvb";
ofd.FilterIndex = 2;
if (ofd.ShowDialog() == DialogResult.OK)
{
con.axWindowsMediaPlayer1.URL = ofd.FileName;//获得音乐文件的路径
FileInfo fi = new FileInfo(ofd.FileName);
con.axWindowsMediaPlayer1.Ctlcontrols.play();//播放
this.lb_Playing.Text = string.Format(" Playing:{0}",fi.Name);
FirstSet();//播放初始设置
//验证歌曲重复,并添加到播放列表
DataSet _dsSong = new DataSet();
_dsSong.ReadXml(Application.StartupPath + "\\musicList.xml", XmlReadMode.ReadSchema);
DataView _dv = new DataView(_dsSong.Tables[0]);
_dv.RowFilter = string.Format("mUrl='{0}'",clsTool.SqlInsertEncode(ofd.FileName));
if (_dv.ToTable().Rows.Count == 0)
XMLAdd();//添加到xml
else
MessageBox.Show("The selected song is already exist");
//加载xml中播放列表
PlayListBind();
}
}
//播放初始化
private void FirstSet()
{
count = 0;
int total = Convert.ToInt32(Math.Truncate(con.axWindowsMediaPlayer1.currentMedia.duration)*10); //进度条总长度
prog_elapsed.Maximum = total;
prog_remain.Maximum = total;
this.prog_elapsed.Value = 0;
this.prog_remain.Value = total;
this.lb_currTotal.Text = con.axWindowsMediaPlayer1.currentMedia.durationString;//总时间
this.slider_prog.Maximum = total;
this.timer1.Enabled = true;
this.cb_HideContr.Checked = true;
}