【发布时间】:2015-06-24 10:43:47
【问题描述】:
我需要一个复选框来激活或停用播放列表(数据表)中曲目的随机播放。如果选中该复选框并且播放曲目结束,则下一个随机曲目应自动开始播放。
这是我在曲目结束时自动调用的事件:
// This event is automatically called when a track has ended
private void mePlayer_MediaEnded(object sender, RoutedEventArgs e)
{
// Check, if the the (last calculated) Index is in the datagrid range
// -1 is used, cause the indexes starts by 0 not 1
if (newIndex >= (dgPlayList.Items.Count - 1))
{
// If the end of the datagrid is reached, set index to 0 for playing the first track
newIndex = 0;
}
else
{
// Is there a following track in the datagrid, then use the next calculated index
newIndex += 1;
}
Console.WriteLine("Set index to: " + newIndex);
// Tell the media player to use the calculated nexIndex
mePlayer.Source = new Uri(playList.Rows[newIndex]["Dateiname"].ToString());
lblFileName.Content = getFileName(playList.Rows[newIndex]["Dateiname"].ToString());
// Starts to play and set it to play
mePlayer.Play();
isPlaying = true;
}
我对 C# 很陌生,只是不知道如何集成播放器在曲目结束后播放随机曲目。
【问题讨论】: