private void OpenBtn_Click(object sender, RoutedEventArgs e) { // Create OpenFileDialog Microsoft.Win32.OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog { Filter = "Media Files | *.mp3;*.m4a;*.wma;*.wav " }; // Launch OpenFileDialog by calling ShowDialog method Nullable <bool> result = openFileDlg.ShowDialog(); // Get the selected file name and display in a TextBox. // Load content of file in a TextBlock if (result == true) { Song s = musicLib.AddSong(openFileDlg.FileName); displayedSongs.Clear(); foreach (DataRow row in musicLib.Songs.Rows) { Song song = musicLib.GetSong(int.Parse(row["id"].ToString())); displayedSongs.Add(song); if (song.Id == s.Id) { dataGrid.SelectedItem = song; } } dataGrid.Items.Refresh(); } }
private void Delete_MenuItemClick(object sender, RoutedEventArgs e) { // Get the song id int songId = findSelectedRowInDataGrid(); // Remove the song from all playlist if (songId != -1 || songId != null && playlistName == "All Music") { Song s = musicLib.GetSong(songId); string name = s.Title; musicLib.DeleteSong(songId); MessageBox.Show(name + " has been removed from the library."); } }
public MainWindow() { InitializeComponent(); musicLib = new MusicLib(); mediaPlayer = new MediaPlayer(); //load playlist list playlistListBox.Items.Add("All Music"); foreach (var playlist in musicLib.Playlists) { playlistListBox.Items.Add(playlist); } //load songs displayedSongs = new List <Song>(); dataGrid.ItemsSource = displayedSongs; foreach (var songId in musicLib.SongIds) { var song = musicLib.GetSong(int.Parse(songId)); displayedSongs.Add(song); } //disable sorting foreach (DataGridColumn column in dataGrid.Columns) { column.CanUserSort = false; } }
public void PlayButton() { mediaPlayer.Stop(); DataRowView selectedsongaddress = dataGrid.SelectedItem as DataRowView; Song selectedsongobject = musicLib.GetSong(Convert.ToInt32(selectedsongaddress.Row["id"])); if (selectedsongobject != null) { mediaPlayer.Open(new Uri(selectedsongobject.Filename)); mediaPlayer.Play(); } else { MessageBox.Show("Please select a song before you hit play"); } }