我目前正在使用c#和winforms播放mp3文件这个tutorial,但我添加了一个datagridview列出的歌曲,现在当我点击一个歌曲在网格中播放的歌曲很好,但它只播放一首歌曲,我想要做的就是一旦歌曲完成播放,移动到列表中的下一首歌曲。我已经尝试过使用Audiolenght的Thread.Sleep作为时间,但它只是停止整个应用程序的工作,直到完成了睡眠,而这完全不是我想要的,对于winforms我有点新奇,所以如果任何人都可以指导我到我需要改变以使其工作,我真的很感激它。这里是我的代码,我已经这么远:Mp3播放类播放歌曲的列表,但等到一个完成前继续
private void dgvTracks_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
PlayFiles(e.RowIndex);
}
public void PlayFiles(int index)
{
try
{
int eof = dgvTracks.Rows.Count;
for (int i = index; index <= eof; i++)
{
if (File.Exists(dsStore.Tables["Track"].Rows[i]["Filepath"].ToString()))
{
PlayFile(dsStore.Tables["Track"].Rows[i]["Filepath"].ToString());
Application.DoEvents();
Thread.Sleep(TimeSpan.FromSeconds(mplayer.AudioLength));
}
else
{
Exception a = new Exception("File doesn't exists");
throw a;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Message, MessageBoxButtons.OK);
}
}
public void PlayFile(string filename)
{
mplayer.Open(filename);
mplayer.Play();
}