1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.ComponentModel;
  4. using System.Windows.Media;
  5.  
  6. namespace MusicPlayer
  7. {
  8.     internal class Backend
  9.     {
  10.         public MediaPlayer Player;
  11.         public ObservableCollection<Song> Playlist;
  12.         private bool _isPlaying;
  13.  
  14.         public Backend()
  15.         {
  16.             Player = new MediaPlayer();
  17.             Playlist = new ObservableCollection<Song>();
  18.             Playing = 0;
  19.             _isPlaying = false;
  20.             Player.MediaEnded += Next;
  21.         }
  22.  
  23.         public int Playing { get; set; }
  24.  
  25.         public void Play()
  26.         {
  27.             var path = new Uri(Playlist[Playing].Path);
  28.             if (Player.Source != path)
  29.                 Player.Open(path);
  30.             Player.Play();
  31.             _isPlaying = true;
  32.             Playlist[Playing].BackgroundColor = Colors.Red;
  33.         }
  34.  
  35.         public void Next(object sender, EventArgs e)
  36.         {
  37.             Next();
  38.         }
  39.  
  40.         public void Next()
  41.         {
  42.             ChangeTrack(Playing + 1);
  43.         }
  44.  
  45.         public void Previous()
  46.         {
  47.             Playlist[Playing].Title = "Played";
  48.             ChangeTrack(Playing - 1);
  49.         }
  50.  
  51.         public void ChangeTrack(int changeTo)
  52.         {
  53.             if (changeTo >= Playlist.Count || changeTo < 0)
  54.                 return;
  55.             Playlist[Playing].BackgroundColor = Colors.White;
  56.             Playing = changeTo;
  57.             Playlist[Playing].BackgroundColor = Colors.Red;
  58.  
  59.             if (_isPlaying)
  60.             {
  61.                 Play();
  62.             }
  63.         }
  64.  
  65.         public void Pause()
  66.         {
  67.             Player.Pause();
  68.             _isPlaying = false;
  69.         }
  70.  
  71.         public void Stop()
  72.         {
  73.             Player.Stop();
  74.             _isPlaying = false;
  75.             Playlist[Playing].BackgroundColor = Colors.White;
  76.         }
  77.     }
  78.  
  79.     internal class Song : INotifyPropertyChanged
  80.     {
  81.         private Color _backgroundColor;
  82.         private string _title;
  83.  
  84.         public Song(string path)
  85.         {
  86.             Path = path;
  87.             Title = path;
  88.             BackgroundColor = Colors.White;
  89.         }
  90.  
  91.         public string Path { get; set; }
  92.  
  93.         public string Title
  94.         {
  95.             get { return _title; }
  96.             set
  97.             {
  98.                 NotifyPropertyChanged("Title");
  99.                 _title = value;
  100.             }
  101.         }
  102.  
  103.         public int Track { get; set; }
  104.  
  105.         public Color BackgroundColor
  106.         {
  107.             get { return _backgroundColor; }
  108.             set
  109.             {
  110.                 NotifyPropertyChanged("BackgroundColor");
  111.                 _backgroundColor = value;
  112.             }
  113.         }
  114.  
  115.         #region INotifyPropertyChanged Members
  116.  
  117.         public event PropertyChangedEventHandler PropertyChanged;
  118.  
  119.         #endregion
  120.  
  121.         private void NotifyPropertyChanged(String info)
  122.         {
  123.             if (PropertyChanged != null)
  124.             {
  125.                 PropertyChanged(this, new PropertyChangedEventArgs(info));
  126.             }
  127.         }
  128.  
  129.  
  130.         public override string ToString()
  131.         {
  132.             return Title;
  133.         }
  134.     }
  135. }