Advertisement
PatrickAupperle

MainWindow.xaml.cs

May 31st, 2011
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement