Mediaelement播放列表重复如何
本文关键字:播放列表 Mediaelement | 更新日期: 2023-09-27 18:11:03
我找不到任何解决方案如何重置索引时,最后一个文件已打开。我有一个mediaelement,从列表框中读取图像,当最后一个图像播放时,我希望它重新启动。就像一个可重复的Mediaelement播放列表。请帮帮我,这件事我真的需要帮助。
Dictionary<string, string> Listbox1Dict = new Dictionary<string, string>();
public static List<string> images = new List<string> { ".JPG", ".JPE", ".BMP", ".GIF", ".PNG" }; // Bildtyper som stöds
public static List<string> movies = new List<string> { ".WMV", ".WAV", ".SWF", ".MP4", ".MPG", ".AVI" }; // Filmtyper som stöds
List<string> paths = new List<string>();
DispatcherTimer dispatcherTimer = new DispatcherTimer();
DispatcherTimer NextImageTimer = new DispatcherTimer();
int x = 20; //Ställa in antal sekunder per bild
private int currentSongIndex = -1;
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
ShowNextImage();
}
private void dispatch()
{
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, x);
}
private void ShowNextImage()
{
if (currentSongIndex == -1)
{
currentSongIndex = Listbox1.SelectedIndex;
}
currentSongIndex++;
var selected = Listbox1.Items[currentSongIndex];
string s = selected.ToString();
if (Listbox1Dict.ContainsKey(s))
{
if (images.Contains(System.IO.Path.GetExtension(s).ToUpperInvariant()))
{
if (currentSongIndex < Listbox1.Items.Count)
{
mediaElement1.Visibility = Visibility.Visible;
SearchBtn.Visibility = Visibility.Hidden;
Listbox1.Visibility = Visibility.Hidden;
FileNameTextBox.Visibility = Visibility.Hidden;
mediaElement1.Source = new Uri(Listbox1Dict[s]);
mediaElement1.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
mediaElement1.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
this.Background = new SolidColorBrush(Colors.Black);
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
mediaElement1.StretchDirection = StretchDirection.Both;
mediaElement1.Stretch = Stretch.Fill;
dispatcherTimer.Start();
}
}
else if (movies.Contains(System.IO.Path.GetExtension(s).ToUpperInvariant()))
{
if (currentSongIndex < Listbox1.Items.Count)
{
dispatcherTimer.Stop();
mediaElement1.Visibility = Visibility.Visible;
Listbox1.Visibility = Visibility.Hidden;
FileNameTextBox.Visibility = Visibility.Hidden;
mediaElement1.Source = new Uri(Listbox1Dict[s]);
mediaElement1.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
mediaElement1.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
this.Background = new SolidColorBrush(Colors.Black);
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
mediaElement1.StretchDirection = StretchDirection.Both;
mediaElement1.Stretch = Stretch.Fill;
}
}
}
}
你能不能这样做:
private void ShowNextImage()
{
if (currentSongIndex == -1)
{
currentSongIndex = Listbox1.SelectedIndex;
}
if (currentSongIndex == ListBox1.Items.Count)
{
currentSongIndex = 0;
}
currentSongIndex++;
....
}