/// <summary> /// Нажатие на кнопку "Следующий трек" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNext_Click(object sender, RoutedEventArgs e) { if ((playlist.Items.Count != 0) && (playlist.SelectedIndex != -1)) { labelNowPlaying.Content = "Now playing:"; BassLike.Next(); slVol.Value = 100; 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])); } else if (Vars.CurrentTrackNumber == Vars.Files.Count) { labelCurrentPlayingName.Content = Vars.GetFileName(Vars.Files[playlist.SelectedIndex]); } if (BassLike.isStopped) { labelLefttime.Content = null; labelRightTime.Content = null; labelCurrentPlayingName.Content = null; } } catch { labelCurrentPlayingName.Content = null; } //***************************************************************************************// string current = Vars.Files[playlist.SelectedIndex]; 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; } //***************************************************************************************// } }
/// <summary> /// Нажатие на кнопку "Плей" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPlay_Click(object sender, MouseButtonEventArgs e) { if ((playlist.Items.Count != 0) && (playlist.SelectedIndex != -1)) { dtimer.Start(); labelNowPlaying.Content = "Now playing:"; string current = Vars.Files[playlist.SelectedIndex]; Vars.CurrentTrackNumber = playlist.SelectedIndex; BassLike.Play(current, BassLike.Volume); 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); 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;; } //***************************************************************************************// } }
/// <summary> /// Изменение позиции воспроизведения /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void slTime_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { labelLefttime.Content = TimeSpan.FromSeconds(BassLike.GetPosOfStream(BassLike.Stream)).ToString(); labelRightTime.Content = TimeSpan.FromSeconds(BassLike.GetTimeOfStream(BassLike.Stream)).ToString(); BassLike.SetPosOfScroll(BassLike.Stream, (int)slTime.Value); }
/// <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; } } }