public bool Play(Music music = null, NetMusic netMusic = null) { var tmpIndex = CurrentIndex; if (music != null) { CurrentIndex = CurrentMusicList.Add(music); } else if (netMusic != null) { CurrentIndex = CurrentMusicList.Add(new Music(netMusic)); } if (CurrentIndex >= 0 && CurrentIndex < CurrentMusicList.Count && CurrentMusicList[CurrentIndex].Origin != NetMusicType.LocalMusic) { var url = ""; if (NetMusicHelper.CheckLink(CurrentMusicList[CurrentIndex].Path)) { url = CurrentMusicList[CurrentIndex].Path; } else { url = NetMusicHelper.GetUrlByNetMusic(CurrentMusicList[CurrentIndex]); if (!NetMusicHelper.CheckLink(url)) { CurrentMusicList.RemoveAt(CurrentIndex); CurrentIndex = tmpIndex; Play(); return(false); } CurrentMusicList[CurrentIndex].Path = url; } if (url.Length <= 0) { CurrentMusicList.Remove(CurrentMusicList[CurrentIndex]); CurrentIndex = tmpIndex; return(false); } } else if (CurrentMusicList.Count > 0 && (CurrentIndex < 0 || CurrentIndex >= CurrentMusicList.Count)) { CurrentIndex = 0; } if (CurrentIndex >= 0 && CurrentIndex < CurrentMusicList.Count) { if (Regex.IsMatch(CurrentMusicList[CurrentIndex].Path, "[http|https]://") && !NetMusicHelper.CheckLink(CurrentMusicList[CurrentIndex].Path)) { CurrentMusicList[CurrentIndex].Path = string.Empty; return(false); } bsp.Stop(); bsp.FileName = CurrentMusicList[CurrentIndex].Path; bsp.Play(); CurrentMusicList[CurrentIndex].Duration = bsp.TotalTime; PlayMusicButton.Visibility = Visibility.Hidden; PauseMusicButton.Visibility = Visibility.Visible; Title = CurrentMusicList[CurrentIndex].Title + " - " + CurrentMusicList[CurrentIndex].Singer; notifyIcon.Text = Title.Length >= 63 ? Title.Substring(0, 60) + "..." : Title; HistoryMusicList.Add(new MusicHistory(CurrentMusicList[CurrentIndex])); SetMiniLable(CurrentMusicList[CurrentIndex]); } return(true); }
private void GetLiric(Music music) { var lyricPath = ""; if (music != null) { if (!string.IsNullOrWhiteSpace(music.LyricPath)) { if (Regex.IsMatch(music.LyricPath, "[a-zA-z]+://[^\\s]*")) { if (NetMusicHelper.CheckLink(music.LyricPath)) { music.LyricPath = NetMusicHelper.GetLyricByUrl(music, music.LyricPath); } else { lyricPath = NetMusicHelper.GetLyricByMusic(music); music.LyricPath = lyricPath; } } lyricPath = music.LyricPath; } else { lyricPath = NetMusicHelper.GetLyricByMusic(music); music.LyricPath = lyricPath; } } Dispatcher.Invoke(new Action(() => { if (!string.IsNullOrWhiteSpace(lyricPath)) { var lrcEncoding = EncodingHelper.GetType(lyricPath); var lrcList = System.IO.File.ReadLines(lyricPath, lrcEncoding); foreach (var item in lrcList) { var pattern = "\\[([0-9.:]*)\\]"; MatchCollection mc = Regex.Matches(item, pattern); foreach (Match line in mc) { Lyric.Add(new LyricLine(Regex.Replace(item, "\\[([0-9.:]*)\\]", ""), TimeSpan.Parse("00:" + line.Groups[1].Value))); } } Lyric = Lyric.OrderBy(m => m.StartTime).ToList(); foreach (var item in Lyric) { item.Content = Regex.Replace(item.Content, "<[\\d]{1,4}>", ""); LyricTextBlock.Inlines.Add(new Run(item.Content + "\n\n")); } Count = LyricTextBlock.Inlines.Count; CurrentLyricIndex = 0; LastLyricLineIndex = -1; haveLyric = true; timer.Start(); } else { haveLyric = false; for (int i = 0; i < 10; i++) { LyricTextBlock.Inlines.Add("\n"); } LyricTextBlock.Inlines.Add(new Run(" 用 心 去 感 受 音 乐\n") { Foreground = Brushes.Red, FontSize = 16 }); } })); }
private void CheckLink() { for (int i = 0; i < PageModel.PlayList.Count; i++) { if (string.IsNullOrWhiteSpace(PageModel.PlayList[i].Path)) { string path = NetMusicHelper.GetUrlByNetMusic(PageModel.PlayList[i]); Dispatcher.Invoke(new Action(() => { PageModel.PlayList[i].Path = path; })); } if ((Regex.IsMatch(PageModel.PlayList[i].Path, "[a-zA-z]+://[^\\s]*") && !NetMusicHelper.CheckLink(PageModel.PlayList[i].Path)) || string.IsNullOrWhiteSpace(PageModel.PlayList[i].Path)) { Dispatcher.Invoke(new Action(() => { PageModel.PlayList[i].Path = ""; PageModel.PlayList[i].IsDisable = true; })); } Dispatcher.Invoke(new Action(() => { CheckLinkLable.Content = i + 1; if (i == PageModel.PlayList.Count - 1) { CheckLinkLable.Visibility = Visibility.Hidden; CheckLinkLodingImage.Visibility = Visibility.Hidden; } })); } }