private void lv_Songs_SelectionChanged(object sender, SelectionChangedEventArgs e) { mp.Open(new Uri(song[lv_Songs.SelectedIndex].Path)); mp.Play(); dt.Start(); bt_PlayPause.IsEnabled = true; bt_PlayPause.IsChecked = true; tx_TrackTitle.Text = song[lv_Songs.SelectedIndex].Title; tx_TrackAlbum.Text = song[lv_Songs.SelectedIndex].Album; tx_TrackArtist.Text = song[lv_Songs.SelectedIndex].Artist; _albumArt = song[lv_Songs.SelectedIndex].albumArt; try { img_AlbumArt.Source = LoadImage(_albumArt[0].PictureData); } catch { } }
private void btnAddTrack_Click(object sender, RoutedEventArgs e) { string fileName = ""; string[] fileDirectories; TimeSpan duration = new TimeSpan(); if (Settings.Default.PreloadOnClick && firstOpen) { try { PreloadSongs(Settings.Default.PreloadDirectory); musicProgress.Maximum = MusicQueue[currentSong].Duration.TotalSeconds; lblMaxTime.Content = MusicQueue[currentSong].Duration.ToString(DefaultSettings.TimeSpanFormat); dataGrid.ItemsSource = MusicQueue; player.Open(new Uri(MusicQueue[currentSong].FilePath)); firstOpen = false; } catch (Exception ex) { MessageBox.Show("Error Loading Files", "File Loading Error"); } } else { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = true; ofd.Filter = "MP3 Files (*.mp3)|*.mp3"; ofd.InitialDirectory = Settings.Default.OpenDirecory; if (ofd.ShowDialog() == true) { fileDirectories = ofd.FileNames; foreach (string fileDir in fileDirectories) { currentDirectory = fileDir; fileName = FormatFileName(fileDir); duration = GetMP3Time(fileDir); MusicFile currentNew = new MusicFile(fileName, currentDirectory, duration); MusicQueue.Add(currentNew); musicProgress.Maximum = currentNew.Duration.TotalSeconds + DefaultSettings.Buffer; lblMaxTime.Content = currentNew.Duration.TotalSeconds.ToString(DefaultSettings.TimeSpanFormat); } dataGrid.SelectedIndex = currentSong; if (firstOpen) { player.Open(new Uri(MusicQueue[currentSong].FilePath)); } firstOpen = false; } dataGrid.ItemsSource = MusicQueue; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public void Load(Uri file) { player = new MediaPlayer(); player.Open(file); }