Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Threading;
- using Microsoft.Win32;
- namespace MusicPlayer
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- private readonly Backend _player;
- private readonly DispatcherTimer _timer;
- public MainWindow()
- {
- InitializeComponent();
- _player = new Backend();
- Playlist.ItemsSource = _player.Playlist;
- _timer = new DispatcherTimer {Interval = new TimeSpan(0, 0, 0, 0, 500)};
- _timer.Tick += Update;
- _timer.Start();
- }
- private void MenuItem_Click(object sender, RoutedEventArgs e)
- {
- Main.Close();
- }
- private void AddButton_Click(object sender, RoutedEventArgs e)
- {
- var openFiles = new OpenFileDialog {Multiselect = true};
- openFiles.ShowDialog();
- string[] files = openFiles.FileNames;
- foreach (string file in files)
- _player.Playlist.Add(new Song(file));
- Playlist.ItemsSource = _player.Playlist;
- }
- private void PlayButton_Click(object sender, RoutedEventArgs e)
- {
- _player.Play();
- PauseButton.Visibility = Visibility.Visible;
- }
- private void nextButton_Click(object sender, RoutedEventArgs e)
- {
- _player.Next();
- }
- private void PreviousButton_Click(object sender, RoutedEventArgs e)
- {
- _player.Previous();
- }
- private void PauseButton_Click(object sender, RoutedEventArgs e)
- {
- _player.Pause();
- PauseButton.Visibility = Visibility.Hidden;
- }
- private void stopButton_Click(object sender, RoutedEventArgs e)
- {
- _player.Stop();
- PauseButton.Visibility = Visibility.Hidden;
- }
- private void Update(object sender, EventArgs e)
- {
- if (_player.Player.NaturalDuration.HasTimeSpan)
- ProgressBar.Value = _player.Player.Position.TotalSeconds/
- _player.Player.NaturalDuration.TimeSpan.TotalSeconds*10;
- }
- private void Playlist_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- _player.ChangeTrack(Playlist.SelectedIndex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement