Esempio n. 1
0
        private void MenuItemRemoveGoToDirectory_Click(object sender, RoutedEventArgs e)
        {
            var fullPath  = MusicViewModel.GetInstance().CurrentlySelectedSong.Path;
            var directory = Path.GetDirectoryName(fullPath);

            Process.Start("explorer.exe", directory);
        }
Esempio n. 2
0
 private MainViewModel()
 {
     SelectedTabIndex   = 0;
     SettingsViewModel  = SettingsViewModel.GetInstance();
     MusicViewModel     = MusicViewModel.GetInstance();
     DiscoveryViewModel = DiscoveryViewModel.GetInstance();
 }
Esempio n. 3
0
        public static void AddEmptyPlaylist(string name)
        {
            Playlist newPlaylist = new Playlist(name);

            MusicViewModel.GetInstance().Playlists.Add(newPlaylist);
            MusicViewModel.GetInstance().PlaylistsNames.Add(newPlaylist.Name);
        }
Esempio n. 4
0
 public static void PlayPauseButtonAction(object parameter)
 {
     if (MusicViewModel.GetInstance().IsPlaying == false)        // if player stopped or paused
     {
         var currentlySelectedSong = MusicViewModel.GetInstance().CurrentlySelectedSong;
         var currentlyPlayedSong   = MusicViewModel.GetInstance().CurrentlyPlayedSong;
         if (currentlyPlayedSong != null)
         {
             if (currentlySelectedSong.Path.Equals(currentlyPlayedSong.Path) == false)
             {
                 PlayAudioFile(currentlySelectedSong.Path);
                 MusicViewModel.GetInstance().CurrentlyPlayedSong = currentlySelectedSong;
                 songIndex = MusicViewModel.GetInstance().FilteredSongs.IndexOf(currentlySelectedSong);
             }
             else
             {
                 ResumeAudioFile();
             }
         }
         else
         {
             PlayAudioFile(currentlySelectedSong.Path);
             MusicViewModel.GetInstance().CurrentlyPlayedSong = currentlySelectedSong;
             songIndex = MusicViewModel.GetInstance().FilteredSongs.IndexOf(currentlySelectedSong);
         }
     }
     else
     {
         PauseAudioFile();
     }
 }
Esempio n. 5
0
 public static void LoadPlaylist(Playlist newPlaylist)
 {
     MusicViewModel.GetInstance().Playlists.Add(newPlaylist);
     System.Windows.Application.Current.Dispatcher.BeginInvoke((Action) delegate
     {
         MusicViewModel.GetInstance().PlaylistsNames.Add(newPlaylist.Name);
     });
 }
Esempio n. 6
0
 public static bool CanRemoveSongFromPlaylist(object parameter)
 {
     if (!MusicViewModel.GetInstance().SelectedPlaylistName.Equals("None"))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 7
0
 public static bool CanClickPlayPauseButton(object parameter)    // May cause bug - test it
 {
     if (MusicViewModel.GetInstance().CurrentlySelectedSong != null || waveOutDevice.PlaybackState == PlaybackState.Playing)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 8
0
 private void MusicGenresComboBox_OnGotMouseCapture(object sender, MouseEventArgs e)
 {
     if (!MusicViewModel.GetInstance().GenresLoaded)
     {
         GenresManager.InitGenres();
     }
     MusicViewModel.GetInstance().GenresLoaded = true;
 }
Esempio n. 9
0
        private void MenuItemAddToPlaylist_OnClick(object sender, RoutedEventArgs e)
        {
            //playlist info
            System.Windows.Controls.MenuItem mi = (MenuItem)e.OriginalSource;
            var playlistName = (string)mi.Header;
            var song         = MusicViewModel.GetInstance().CurrentlySelectedSong;

            PlaylistManager.AddSongToPlaylist(playlistName, song);
        }
Esempio n. 10
0
        public static bool CanClickNextSongButton(object parameter)
        {
            var currentlyPlayedSongIndex = songIndex;

            if (currentlyPlayedSongIndex < MusicViewModel.GetInstance().FilteredSongs.Count - 1)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 11
0
        public static void PreviousSongAction(object parameter)
        {
            var newIndex         = songIndex - 1;
            var nextlyPlayedSong = MusicViewModel.GetInstance().FilteredSongs.ElementAt(newIndex);

            MusicViewModel.GetInstance().CurrentlySelectedSong = nextlyPlayedSong;
            MusicViewModel.GetInstance().CurrentlyPlayedSong   = nextlyPlayedSong;
            songIndex--;
            PlayAudioFile(nextlyPlayedSong.Path);
        }
Esempio n. 12
0
        public static void StopPlayer()
        {
            var instance = MusicViewModel.GetInstance();

            instance.CurrentlySelectedSong =
                instance.FilteredSongs.FirstOrDefault();
            instance.IsPlaying           = false;
            instance.TrackPosition       = TimeSpan.Zero;
            instance.TrackTotalTime      = TimeSpan.Zero;
            instance.CurrentlyPlayedSong = null;
        }
Esempio n. 13
0
        private void ContextMenuPlay_OnClick(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.MenuItem mi = (MenuItem)e.OriginalSource;
            var actionName = (string)mi.Header;

            if (actionName.Equals("Play") && MusicViewModel.GetInstance().CurrentlySelectedSong != null)
            {
                MusicPlayer.MusicPlayer.PlayAudioFile(MusicViewModel.GetInstance().CurrentlySelectedSong.Path);
                MusicViewModel.GetInstance().CurrentlyPlayedSong = MusicViewModel.GetInstance().CurrentlySelectedSong;
            }
        }
Esempio n. 14
0
        public static void RemoveSongFromPlaylist(object parameter)
        {
            var currentlySelectedSong     = MusicViewModel.GetInstance().CurrentlySelectedSong;
            var currentlySelectedPlaylist = MusicViewModel.GetInstance().Playlists.
                                            FirstOrDefault(p => p.Name.Equals(MusicViewModel.GetInstance().SelectedPlaylistName));

            if (currentlySelectedPlaylist != null)
            {
                PlaylistManager.RemoveSongFromPlaylist(currentlySelectedPlaylist.Name, currentlySelectedSong);
            }
            var par = parameter;
        }
Esempio n. 15
0
        public static void AddSongToPlaylist(string playlistName, Song song)
        {
            var playlist = MusicViewModel.GetInstance().Playlists
                           .FirstOrDefault(p => p.Name.Equals(playlistName));

            if (playlist != null)
            {
                playlist.Songs.Add(song);

                SavePlaylistToXML(playlist);
            }
        }
Esempio n. 16
0
        public static void MouseDoubleClickPlayAction(object parameter)
        {
            Song song        = (Song)parameter;
            var  currentSong = MusicViewModel.GetInstance().CurrentlyPlayedSong;

            if (currentSong == null || song.Path != currentSong.Path)
            {
                MusicViewModel.GetInstance().CurrentlyPlayedSong = song;
                songIndex = MusicViewModel.GetInstance().FilteredSongs.IndexOf(song);
                PlayAudioFile(song.Path);
            }
        }
Esempio n. 17
0
 private void SearchBox_OnKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Escape)
     {
         var textBox = (TextBox)sender;
         if (textBox != null)
         {
             textBox.Text = string.Empty;
             MusicViewModel.GetInstance().FilterSongs(null);
         }
     }
 }
Esempio n. 18
0
        public static void RemoveSongFromPlaylist(string playlistName, Song song)
        {
            var playlist = MusicViewModel.GetInstance().Playlists
                           .FirstOrDefault(p => p.Name.Equals(playlistName));

            if (playlist != null)
            {
                var songToRemoveIndex =
                    playlist.Songs.IndexOf(playlist.Songs.FirstOrDefault(s => s.Path.Equals(song.Path)));
                playlist.Songs.RemoveAt(songToRemoveIndex);
                MusicViewModel.GetInstance().FilteredSongs.RemoveAt(songToRemoveIndex);
                SavePlaylistToXML(playlist);
            }
        }
Esempio n. 19
0
 public static void MuteSoundAction(object parameter)
 {
     if (!MusicViewModel.GetInstance().IsMuted)
     {
         MusicViewModel.GetInstance().IsMuted = true;
         waveOutDevice.Volume = 0.0f;
     }
     else
     if (MusicViewModel.GetInstance().IsMuted)
     {
         MusicViewModel.GetInstance().IsMuted = false;
         waveOutDevice.Volume = MusicViewModel.GetInstance().Volume / 100;
     }
 }
Esempio n. 20
0
        private void ChangeMusicDirectory(object sender, SelectionChangedEventArgs e)
        {
            var addedItem = (string)e.AddedItems[0];

            if (e.RemovedItems.Count > 0)
            {
                var musicViewModel = MusicViewModel.GetInstance();
                musicViewModel.RefreshSelectedSong();
                System.Threading.Tasks.Task.Run(() => musicViewModel.LoadSongsToMusicView(
                                                    musicViewModel.LoadMusicFilesNamesFromDirectories(musicViewModel.GetMusicDirectories())));

                //musicViewModel.LoadSongsToMusicView(
                //    musicViewModel.LoadMusicFilesNamesFromDirectories(musicViewModel.GetMusicDirectories()));
            }
        }
Esempio n. 21
0
 public static void PlayAudioFile(string fileName)
 {
     CloseWaveOut();
     waveOutDevice   = new NAudio.Wave.WaveOut();
     audioFileReader = new MediaFoundationReader(fileName);
     //audioFileReader = new AudioFileReader(fileName);
     MusicViewModel.GetInstance().TrackTotalTime = audioFileReader.TotalTime;
     MusicViewModel.GetInstance().IsPlaying      = true;
     audioFileReader.Position       = 0;
     waveOutDevice.PlaybackStopped += SongEndedAction;
     timer.Elapsed  += UpdateCurrentTrackTime;
     timer.AutoReset = true;
     waveOutDevice.Init(audioFileReader);
     timer.Enabled = true;
     waveOutDevice.Play();
 }
Esempio n. 22
0
        private async void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            await Task.Run(() => PlaylistManager.InitPlaylists());

            if (App.StartupSongsPaths.Count > 0)
            {
                MusicViewModel.GetInstance().LoadSongsToMusicView(App.StartupSongsPaths);
                MusicViewModel.GetInstance().RefreshMusicDirectories();
            }
            else
            {
                await MusicViewModel.GetInstance().RefreshMusicDirectoriesAndLoadSongsAsync();
            }

            _applicationLoaded = true;

            DiscoveryViewModel.GetInstance().InitSpotifyAPI();
        }
Esempio n. 23
0
        public static void InitGenres()
        {
            MusicViewModel.GetInstance().MyMusicGenres = new ObservableCollection <string> {
                "All"
            };

            foreach (var song in MusicViewModel.GetInstance().Songs)
            {
                var genres = song.Genres as IEnumerable <string>;
                if (genres.Any())
                {
                    genres = genres.Except(MusicViewModel.GetInstance().MyMusicGenres);
                    foreach (var genre in genres)
                    {
                        MusicViewModel.GetInstance().MyMusicGenres.Add(genre);
                    }
                }
            }
        }
Esempio n. 24
0
        private void PlaylistsComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MainWindow.IsApplicationLoaded() == false)
            {
                return;
            }

            var addedItem = (string)e.AddedItems[0];

            if (!addedItem.Equals("None"))
            {
                MusicViewModel.GetInstance().SelectedPlaylistName = addedItem;
                MusicViewModel.GetInstance().LoadSongsFromPlaylistToMusicView();
            }
            else
            {
                MusicViewModel.GetInstance().SelectedPlaylistName = addedItem;
                MusicViewModel.GetInstance().LoadSongsFromPlaylistToMusicView();
            }
        }
Esempio n. 25
0
 private void MenuItemRemoveFromQueue_Click(object sender, RoutedEventArgs e)
 {
     MusicViewModel.GetInstance().FilteredSongs.Remove(MusicViewModel.GetInstance().CurrentlySelectedSong);
 }
Esempio n. 26
0
 public static void ResumeAudioFile()
 {
     waveOutDevice?.Play();
     MusicViewModel.GetInstance().IsPlaying = true;
 }
Esempio n. 27
0
 public static void PauseAudioFile()
 {
     waveOutDevice?.Pause();
     MusicViewModel.GetInstance().IsPlaying = false;
 }
Esempio n. 28
0
 public static void UpdateCurrentTrackTime(Object source, ElapsedEventArgs e)       // Method for timer
 {
     MusicViewModel.GetInstance().TrackPosition = audioFileReader.CurrentTime;
 }
Esempio n. 29
0
 public MusicView()
 {
     InitializeComponent();
     dataModel        = MusicViewModel.GetInstance();
     this.DataContext = dataModel;
 }
Esempio n. 30
0
 private void MusicGenresComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     MusicViewModel.GetInstance().LoadSongsByGenre();
 }