public Playing() { this.InitializeComponent(); // // 绑定歌曲更改事件 MainPage.player.SongChanged += UpdateInfo; MainPage.player.PlayerStateChanged += PlayModeChange; // 更新歌曲信息 MusicName.Text = MainPage.player.SongName; Vocal.Text = MainPage.player.VocalName; BackgroundImage.Source = new BitmapImage(new Uri(MainPage.player.SongImage)); // 判断是否显示分享评论 if (MainPage.player.SongId == "") { Share.Visibility = Visibility.Collapsed; Comment.Visibility = Visibility.Collapsed; } else { Share.Visibility = Visibility.Visible; Comment.Visibility = Visibility.Visible; #region 载入歌词 // 多线程加载歌词 lyricTimer = new Timer(new TimerCallback(LyricTick), null, Timeout.Infinite, 100); new Thread(a => { string jsonText = GetTools.GetRequest(MainPage.player.songObject.assestLink.Lyric); Invoke(new Action(delegate { Lyric getLyric = Lyric.ParseLyric(jsonText); lrcs.Clear(); for (int i = 0; i != getLyric.parse.Length; i++) { lrcs.Add(getLyric.parse[i]); } loadingComplete = true; })); lyricTimer.Change(0, 100); GC.Collect(); }).Start(); #endregion } }
private void UpdateInfo(Player sender, object args) { Invoke(new Action(delegate { lyricTimer.Dispose(); MusicName.Text = sender.SongName; Vocal.Text = sender.VocalName; var image = new BitmapImage(); image.UriSource = new Uri(sender.SongImage); BackgroundImage.Source = image; if (MainPage.player.SongId == "") { Share.Visibility = Visibility.Collapsed; Comment.Visibility = Visibility.Collapsed; } else { Share.Visibility = Visibility.Visible; Comment.Visibility = Visibility.Visible; } })); // 多线程加载歌词 #region 加载歌词 new Thread(a => { string jsonText = GetTools.GetRequest(MainPage.player.songObject.assestLink.Lyric); Invoke(new Action(delegate { loadingComplete = false; Lyric getLyric = Lyric.ParseLyric(jsonText); lrcs.Clear(); foreach (WordWithTranslate lycTemp in getLyric.parse) { lrcs.Add(lycTemp); } NowLyricWord = -1; loadingComplete = true; lyricTimer = new Timer(new TimerCallback(LyricTick), null, 0, 100); })); }).Start(); #endregion }