1
私はC#WPFで自分の音楽プレーヤーを作っています。しかし、曲が完成したら自動的に次のファイルをプレイリストで再生させることはできません。私は、プレイの進行状況、チェックボックス、次の前のボタンを表示するスライダーを持っています。ここでファイルが完成したら自動的に次のファイルをプレイリストで再生する方法は?
は、次のボタンのコードです:
private void btnNext_Click(object sender, RoutedEventArgs e)
{
if (listBox.SelectedIndex < listBox.Items.Count - 1)
{
listBox.SelectedIndex = listBox.SelectedIndex + 1;
TagLib.File tagFile = TagLib.File.Create((listBox.SelectedValue).ToString());
string album = tagFile.Tag.Album;
string artist = tagFile.Tag.FirstAlbumArtist;
string title = tagFile.Tag.Title;
uint year = tagFile.Tag.Year;
string genre = tagFile.Tag.FirstGenre;
lblName.Content = artist + " - " + title;
lblAlbum.Content = album;
lblArtist.Content = artist;
lblTitle.Content = title;
lblYear.Content = year;
lblGenre.Content = genre;
lblBit.Content = tagFile.Properties.AudioBitrate + " kbps";
lblTime2.Content = tagFile.Properties.Duration.ToString(@"mm\:ss");
mediaPlayer.Open(new Uri((listBox.SelectedValue).ToString()));
mediaPlayer.Play();
btnPlay2.Visibility = Visibility.Hidden;
btnPause.IsEnabled = true;
}
}
そして、ここでは、スライダのためのコードは次のとおりです。
private void sliProgress_DragStarted(object sender, DragStartedEventArgs e)
{
userIsDraggingSlider = true;
}
private void sliProgress_DragCompleted(object sender, DragCompletedEventArgs e)
{
userIsDraggingSlider = false;
mediaPlayer.Position = TimeSpan.FromSeconds(sliProgress.Value);
}
private void sliProgress_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
lblTime.Content = TimeSpan.FromSeconds(sliProgress.Value).ToString(@"mm\:ss");
}
私はそのチェックボックスに[次へ]ボタンで手順を実装しようとしていますソング/ファイルの最大継続時間(lblTime2)と進行時間(lblTime)が等しいときを比較することによってクリックされたとき:
private void radioAll_Checked(object sender, RoutedEventArgs e)
{
if (lblTime.Content.ToString() == lblTime2.Content.ToString())
{
if (listBox.SelectedIndex < listBox.Items.Count - 1)
{
listBox.SelectedIndex = listBox.SelectedIndex + 1;
TagLib.File tagFile = TagLib.File.Create((listBox.SelectedValue).ToString());
string album = tagFile.Tag.Album;
string artist = tagFile.Tag.FirstAlbumArtist;
string title = tagFile.Tag.Title;
uint year = tagFile.Tag.Year;
string genre = tagFile.Tag.FirstGenre;
lblName.Content = artist + " - " + title;
lblAlbum.Content = album;
lblArtist.Content = artist;
lblTitle.Content = title;
lblYear.Content = year;
lblGenre.Content = genre;
lblBit.Content = tagFile.Properties.AudioBitrate + " kbps";
lblTime2.Content = tagFile.Properties.Duration.ToString(@"mm\:ss");
mediaPlayer.Open(new Uri((listBox.SelectedValue).ToString()));
mediaPlayer.Play();
}
}
}
残念ながら、それはまったく機能しません。私は何かを逃したのですか?私は何をすべきか?
ご協力いただきありがとうございました! –
私はより多くの助けになるためにこの[スレッド](https://stackoverflow.com/questions/24320487/how-to-run-the-mediaplayer-on-repeat-mode-in-c-sharp-wpf)を読んでいます。これで、ファイルを連続して繰り返すことができます。 –
@StevenAldo優れた良い! :) – MickyD