我正在製作一個小型媒體播放器,將媒體文件添加到作爲mediaelement播放列表的列表框中。當我點擊列表框中的一個項目時,它開始播放。我想要做的是在當前結束後讓媒體元素自動開始播放列表框中的下一首歌曲/視頻。自動播放列表框中的下一個項目
以下是我的歌曲添加到列表框中:
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
foreach (string file in ofd.FileNames)
{
FileInfo fileName = new FileInfo(file);
listBox.Items.Add(fileName);
}
}
這裏就是我可以點擊列表框中的項目,並開始播放
private void Button_Click(object sender, RoutedEventArgs e)
{
System.Windows.Controls.Button prevButton = player.Tag as System.Windows.Controls.Button;
System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
FileInfo fileInfo = button.DataContext as FileInfo;
// If a file is playing, stop it
if (prevButton != null)
{
player.Tag = null;
player.Stop();
prevButton.Background = Brushes.White;
// if the one thats playing is the one that was clicked -> don't play it
if (prevButton == button)
return;
}
// Play the one that was clicked
player.Tag = button;
player.Source = new Uri(fileInfo.FullName);
player.Play();
}
'player'是什麼類? – zimdanen
這與mediaelement相同 – spex