0

我找不到任何解决方案如何在打开最后一个文件时重置索引。我有一个从列表框中读取图像的媒体元素,当播放完最后一张图像时,我希望它重新启动。就像一个可重复的 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;
                }
            }
        }
    }
4

1 回答 1

1

你不能做类似的事情:

private void ShowNextImage()
{
    if (currentSongIndex == -1)
    {
        currentSongIndex = Listbox1.SelectedIndex;
    }
    if (currentSongIndex == ListBox1.Items.Count)
    {
        currentSongIndex = 0;
    }
    currentSongIndex++;
    ....
}
于 2013-04-25T12:36:08.507 回答