/// <summary> /// Нажатие на кнопку "Стоп" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStop_Click(object sender, RoutedEventArgs e) { BassLike.Stop(); dtimer.Stop(); slTime.Value = 0; labelLefttime.Content = "00:00:00"; labelRightTime.Content = "00:00:00"; labelNowPlaying.Content = " "; labelCurrentPlayingName.Content = " "; }
/// <summary> /// Нажатие на кнопку "Удалить трек из плейлиста" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelete_Click(object sender, RoutedEventArgs e) { if ((playlist.Items.Count != 0) && (playlist.SelectedIndex != -1)) { BassLike.Stop(); Vars.CurrentTrackNumber = playlist.SelectedIndex; Vars.Files.Remove(Vars.Files[playlist.SelectedIndex]); playlist.Items.RemoveAt(playlist.SelectedIndex); var uri = new Uri("pack://application:,,,/Resources/nocover.png"); var img = new BitmapImage(uri); image.Source = img; labelLefttime.Content = "00:00:00"; labelRightTime.Content = "00:00:00"; labelNowPlaying.Content = null; labelCurrentPlayingName.Content = null; } }
/// <summary> /// Описано задание значений максимальной длины трека, минимально длины трека и значения ползунка /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dtimer_Tick(object sender, EventArgs e) { if ((playlist.Items.Count != 0) && (playlist.SelectedIndex != -1)) { slTime.Minimum = 0; //Получаем значения посекундного измения времени трека при проигывании + вследствие этого движется ползунок slTime.Maximum = BassLike.GetTimeOfStream(BassLike.Stream); slTime.Value = BassLike.GetPosOfStream(BassLike.Stream); if (BassLike.ToNextTrack() == true) { if ((playlist.Items.Count != 0) && (playlist.SelectedIndex != -1)) { BassLike.Stop(); btnNext_Click(this, new RoutedEventArgs()); btnPrev_Click(this, new RoutedEventArgs()); btnPlay_Click(this, new RoutedEventArgs()); slVol.Value = 100; labelNowPlaying.Content = "Now playing:"; BassLike.Next(); labelLefttime.Content = TimeSpan.FromSeconds(BassLike.GetPosOfStream(BassLike.Stream)).ToString(); labelRightTime.Content = TimeSpan.FromSeconds(BassLike.GetTimeOfStream(BassLike.Stream)).ToString(); slTime.Maximum = BassLike.GetTimeOfStream(BassLike.Stream); slTime.Value = BassLike.GetPosOfStream(BassLike.Stream); try { if (Vars.Files.Count >= Vars.CurrentTrackNumber + 1) { ++playlist.SelectedIndex; labelCurrentPlayingName.Content = Vars.GetFileName((Vars.Files[Vars.CurrentTrackNumber])); } if (Vars.CurrentTrackNumber == Vars.Files.Count) { labelCurrentPlayingName.Content = Vars.GetFileName(Vars.Files[playlist.SelectedIndex]); } if (Vars.CurrentTrackNumber == 0) { playlist.SelectedIndex = 0; labelCurrentPlayingName.Content = Vars.GetFileName(Vars.Files[0]); } if (BassLike.isStopped) { labelLefttime.Content = null; labelRightTime.Content = null; labelCurrentPlayingName.Content = null; } } catch { labelCurrentPlayingName.Content = null; } } //*********************************************************// string current = Vars.Files[playlist.SelectedIndex]; Vars.CurrentTrackNumber = playlist.SelectedIndex; labelCurrentPlayingName.Content = Vars.GetFileName(current); try { TagLib.File f = new TagLib.Mpeg.AudioFile(current); TagLib.IPicture pic = f.Tag.Pictures[0]; var mStream = new MemoryStream(pic.Data.Data); mStream.Seek(0, SeekOrigin.Begin); BitmapImage bm = new BitmapImage(); bm.BeginInit(); bm.StreamSource = mStream; bm.EndInit(); System.Windows.Controls.Image cover = new System.Windows.Controls.Image(); cover.Source = bm; image.Source = bm; } catch { var uri = new Uri("pack://application:,,,/Resources/nocover.png"); var img = new BitmapImage(uri); image.Source = img; } //***************************************************************************************// } if (BassLike.endPlaylist) { btnStop_Click(this, new RoutedEventArgs()); playlist.SelectedIndex = Vars.CurrentTrackNumber = 0; BassLike.endPlaylist = false; } } }