2013-04-25 45 views
0

我找不到任何解決方案如何在最後一個文件打開時重置索引。 我有一個mediaelement從列表框中讀取圖像,當最後一張圖像被播放時,我希望它重新啓動。就像一個可重複的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; 
       } 
      } 
     } 
    } 

回答

1

廣東話你做這樣的事情:

private void ShowNextImage() 
{ 
    if (currentSongIndex == -1) 
    { 
     currentSongIndex = Listbox1.SelectedIndex; 
    } 
    if (currentSongIndex == ListBox1.Items.Count) 
    { 
     currentSongIndex = 0; 
    } 
    currentSongIndex++; 
    .... 
} 
+0

爲什麼我沒有想過這個問題? 謝謝,先生!謝謝! – Sneakybastardd 2013-04-25 12:44:15