Want more features on Pastebin? Sign Up, it's FREE!
Guest

MainWindow.xaml.cs

By: PatrickAupperle on May 31st, 2011  |  syntax: C#  |  size: 2.49 KB  |  views: 184  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Input;
  4. using System.Windows.Threading;
  5. using Microsoft.Win32;
  6.  
  7. namespace MusicPlayer
  8. {
  9.     /// <summary>
  10.     /// Interaction logic for MainWindow.xaml
  11.     /// </summary>
  12.     public partial class MainWindow : Window
  13.     {
  14.         private readonly Backend _player;
  15.         private readonly DispatcherTimer _timer;
  16.  
  17.         public MainWindow()
  18.         {
  19.             InitializeComponent();
  20.             _player = new Backend();
  21.             Playlist.ItemsSource = _player.Playlist;
  22.             _timer = new DispatcherTimer {Interval = new TimeSpan(0, 0, 0, 0, 500)};
  23.             _timer.Tick += Update;
  24.             _timer.Start();
  25.         }
  26.  
  27.         private void MenuItem_Click(object sender, RoutedEventArgs e)
  28.         {
  29.             Main.Close();
  30.         }
  31.  
  32.         private void AddButton_Click(object sender, RoutedEventArgs e)
  33.         {
  34.             var openFiles = new OpenFileDialog {Multiselect = true};
  35.             openFiles.ShowDialog();
  36.             string[] files = openFiles.FileNames;
  37.             foreach (string file in files)
  38.                 _player.Playlist.Add(new Song(file));
  39.             Playlist.ItemsSource = _player.Playlist;
  40.         }
  41.  
  42.         private void PlayButton_Click(object sender, RoutedEventArgs e)
  43.         {
  44.             _player.Play();
  45.             PauseButton.Visibility = Visibility.Visible;
  46.         }
  47.  
  48.         private void nextButton_Click(object sender, RoutedEventArgs e)
  49.         {
  50.             _player.Next();
  51.         }
  52.  
  53.         private void PreviousButton_Click(object sender, RoutedEventArgs e)
  54.         {
  55.             _player.Previous();
  56.         }
  57.  
  58.         private void PauseButton_Click(object sender, RoutedEventArgs e)
  59.         {
  60.             _player.Pause();
  61.             PauseButton.Visibility = Visibility.Hidden;
  62.         }
  63.  
  64.         private void stopButton_Click(object sender, RoutedEventArgs e)
  65.         {
  66.             _player.Stop();
  67.             PauseButton.Visibility = Visibility.Hidden;
  68.         }
  69.  
  70.         private void Update(object sender, EventArgs e)
  71.         {
  72.             if (_player.Player.NaturalDuration.HasTimeSpan)
  73.                 ProgressBar.Value = _player.Player.Position.TotalSeconds/
  74.                                     _player.Player.NaturalDuration.TimeSpan.TotalSeconds*10;
  75.         }
  76.  
  77.         private void Playlist_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  78.         {
  79.             _player.ChangeTrack(Playlist.SelectedIndex);
  80.         }
  81.     }
  82. }
clone this paste RAW Paste Data