//moving songs from playlist to playlist private void AddToPlaylistButton_Click(object sender, RoutedEventArgs e) { List <SongViewModel> selectedSongs; switch (songListTabControl.SelectedIndex) { case 1: //tab 1, search tab selectedSongs = searchListbox.SelectedItems.Cast <SongViewModel>().ToList(); break; default: //tab 0, song list selectedSongs = songListBox.SelectedItems.Cast <SongViewModel>().ToList(); break; } if (selectedSongs.Count <= 0) { MessageBox.Show("No songs are selected", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (((PlaylistItemViewModel)targetPlaylistComboBox.SelectedItem).Name.Equals(currentPlaylist.Name)) { MessageBox.Show("The source and destination playlist cannot be the same", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } PlaylistItemViewModel item = PlaylistItems[targetPlaylistComboBox.SelectedIndex]; PlaylistViewModel targetPlaylist = serializer.DeserializePlaylist(item.Path); MessageBoxResult result = MessageBox.Show(string.Format("Would you like to copy {0} songs from {1} to {2}", selectedSongs.Count, currentPlaylist.Name, targetPlaylist.Name), "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { int largestInd = 0; for (int i = 0; i < targetPlaylist.Songs.Count; i++) { if (targetPlaylist.Songs[i].Order > largestInd) { largestInd = targetPlaylist.Songs[i].Order; } } for (int i = 0; i < selectedSongs.Count; i++) { SongViewModel song = new SongViewModel(selectedSongs[i]); song.Order = largestInd + i + 1; targetPlaylist.Songs.Add(song); } serializer.Serialize(targetPlaylist); Console.WriteLine("moved " + selectedSongs.Count + " to " + targetPlaylist.Name); } }
private void Search(string path) { ObservableCollection <SongViewModel> songs = new ObservableCollection <SongViewModel>(); int songCount = 0; string[] directories = Directory.GetDirectories(path); foreach (var d in directories) { IEnumerable <string> meta = Directory.EnumerateFiles(d, "*.osu", SearchOption.TopDirectoryOnly); string element = meta.FirstOrDefault(); if (element == null || element.Length == 0) { continue; } using (StreamReader s = new StreamReader(element)){ int lineCount = 0; string line, audioName, title, artist; line = audioName = title = artist = ""; while ((line = s.ReadLine()) != null && lineCount < 40) { if (line.Contains("AudioFilename:")) { audioName = line.Substring(("AudioFilename:").Length + 1); } else if (line.Contains("Title:")) { title = line.Substring(("Title:").Length); } else if (line.Contains("Artist:")) { artist = line.Substring(("Artist:").Length); break; } lineCount++; } SongViewModel song = new SongViewModel(songCount, title, artist, new DirectoryInfo(d).Name + "\\" + audioName); Console.WriteLine(song); songs.Add(song); songCount++; } percentCompletion = (float)songCount / directories.Length * 100f; } Songs = songs; searchCompleted = true; Console.WriteLine("*********************" + songs.Count); }
private void PlaySong() { //get selected song source from the currently selected tab. "all song" and "search" tab SongViewModel selected = songListTabControl.SelectedIndex == 1 ? (SongViewModel)searchListbox.SelectedItem : (SongViewModel)songListBox.SelectedItem; if (selected == null) { return; } if (!musicPlayer.HasAudio || !currentSong.CheckEquals(selected)) { currentSong = selected; Console.WriteLine("playing: " + selectedFolderPath + "\\" + currentSong.Path); musicPlayer.Open(currentSong, selectedFolderPath + "\\" + currentSong.Path, (MMDevice)audioOutputComboBox.SelectedItem); Console.WriteLine((MMDevice)audioOutputComboBox.SelectedItem); } musicPlayer.Play(); }