Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Windows.Media;
- namespace MusicPlayer
- {
- internal class Backend
- {
- public MediaPlayer Player;
- public ObservableCollection<Song> Playlist;
- private bool _isPlaying;
- public Backend()
- {
- Player = new MediaPlayer();
- Playlist = new ObservableCollection<Song>();
- Playing = 0;
- _isPlaying = false;
- Player.MediaEnded += Next;
- }
- public int Playing { get; set; }
- public void Play()
- {
- var path = new Uri(Playlist[Playing].Path);
- if (Player.Source != path)
- Player.Open(path);
- Player.Play();
- _isPlaying = true;
- Playlist[Playing].BackgroundColor = Colors.Red;
- }
- public void Next(object sender, EventArgs e)
- {
- Next();
- }
- public void Next()
- {
- ChangeTrack(Playing + 1);
- }
- public void Previous()
- {
- Playlist[Playing].Title = "Played";
- ChangeTrack(Playing - 1);
- }
- public void ChangeTrack(int changeTo)
- {
- if (changeTo >= Playlist.Count || changeTo < 0)
- return;
- Playlist[Playing].BackgroundColor = Colors.White;
- Playing = changeTo;
- Playlist[Playing].BackgroundColor = Colors.Red;
- if (_isPlaying)
- {
- Play();
- }
- }
- public void Pause()
- {
- Player.Pause();
- _isPlaying = false;
- }
- public void Stop()
- {
- Player.Stop();
- _isPlaying = false;
- Playlist[Playing].BackgroundColor = Colors.White;
- }
- }
- internal class Song : INotifyPropertyChanged
- {
- private Color _backgroundColor;
- private string _title;
- public Song(string path)
- {
- Path = path;
- Title = path;
- BackgroundColor = Colors.White;
- }
- public string Path { get; set; }
- public string Title
- {
- get { return _title; }
- set
- {
- NotifyPropertyChanged("Title");
- _title = value;
- }
- }
- public int Track { get; set; }
- public Color BackgroundColor
- {
- get { return _backgroundColor; }
- set
- {
- NotifyPropertyChanged("BackgroundColor");
- _backgroundColor = value;
- }
- }
- #region INotifyPropertyChanged Members
- public event PropertyChangedEventHandler PropertyChanged;
- #endregion
- private void NotifyPropertyChanged(String info)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(info));
- }
- }
- public override string ToString()
- {
- return Title;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement