private async void Next(object sender, RoutedEventArgs e) { if (DurationTimer != null) { DurationTimer.Stop(); DurationTimer = null; } if (DGJ.IsRunning) { var song = await DGJ.NextSong(); if (song == null) { IsPlaying = false; Player.Stop(); Song.Text = "没有歌曲"; Album.Text = "欢迎点歌"; Duration.Text = "--:--/--:--"; } else { Player.Source = new Uri(song.Source); Song.Text = $"{song.Artist} - {song.Name}"; Album.Text = $"专辑:{song.Album}"; if (DurationTimer != null) { DurationTimer.Stop(); DurationTimer = null; } DurationTimer = new DispatcherTimer(); DurationTimer.Interval = TimeSpan.FromSeconds(1); DurationTimer.Tick += (s, e) => { Duration.Text = $"{Player.Position:mm\\:ss}/{song.Duration:mm\\:ss}"; }; DurationTimer.Start(); Player.Play(); } } else { IsPlaying = false; Song.Text = "连接已断开或直播已结束"; Album.Text = "按ESC关闭点歌姬"; Duration.Text = "--:--/--:--"; } }
private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { DGJ.OnConnect += () => { Song.Text = "没有歌曲"; Album.Text = "欢迎点歌"; }; DGJ.OnExit += () => { if (!IsPlaying) { Song.Text = "连接已断开或直播已结束"; Album.Text = "按ESC关闭点歌姬"; Duration.Text = "--:--/--:--"; } }; DGJ.OnAddSong += song => { if (!IsPlaying) { IsPlaying = true; Next(null, null); } }; var ready = await DGJ.Initialize(); Trace.WriteLine("DGJ initialized"); #if DEBUG await DGJ.AddSong("喜欢你 乌拉喵"); await DGJ.AddSong("笨蛋AC娘 AC娘本体"); await DGJ.AddSong("巡年之礼"); await DGJ.AddSong("爱在A站 纱朵"); await DGJ.AddSong("为A而战 AC娘本体"); await DGJ.AddSong("命犯桃花 FLASH1NG"); await DGJ.AddSong("循环 尧顺宇"); #endif }