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; } })); } }
public void GetNetMusicList(string searchStr, int offset, NetMusicType netMusicType) { int count = 0; Dispatcher.Invoke(new Action(() => { LodingImage.Visibility = Visibility.Visible; if (offset == 0) { CountLabel.DataContext = $"搜索\"{searchStr}\""; } })); var t = NetMusicHelper.GetNetMusicList(searchStr, offset, netMusicType, out count); Dispatcher.Invoke(new Action(() => { ParentWindow.NetMusicList.Clear(); })); foreach (var item in t) { Dispatcher.Invoke(new Action(() => { ParentWindow.NetMusicList.Add(item); })); } Dispatcher.Invoke(new Action(() => { if (offset == 0) { CountLabel.DataContext = $"搜索\"{searchStr}\", 找到 {count} 首单曲"; } if (offset == 0 && count <= 30) { LastPageButton.IsEnabled = false; NextPageButton.IsEnabled = false; } else if (offset == 0) { LastPageButton.IsEnabled = false; NextPageButton.IsEnabled = true; } else if (offset / 30 + 1 == count / 30 + (count % 30 == 0 ? 0 : 1)) { LastPageButton.IsEnabled = true; NextPageButton.IsEnabled = false; } else { LastPageButton.IsEnabled = true; NextPageButton.IsEnabled = true; } MusicCount = count; LodingImage.Visibility = Visibility.Hidden; })); }
private void GetPlayList(int offset, NetMusicType pageType) { if (!(ParentWindow?.IsConnectInternet() ?? false)) { return; } int count = 0; Dispatcher.Invoke(new Action(() => { LodingImage.Visibility = Visibility.Visible; })); var list = NetMusicHelper.GetPlayList(Offset, PageType, out count); DataTable pic = new DataTable(); pic.Columns.Add("Name"); pic.Columns.Add("ImgUrl"); pic.Columns.Add("Url"); foreach (var item in list) { pic.Rows.Add(item.Name, item.ImgUrl, item.Url); } Dispatcher.Invoke(new Action(() => { if (count <= 1) { LastPageButton.IsEnabled = false; NextPageButton.IsEnabled = false; } else if (offset == 0) { LastPageButton.IsEnabled = false; NextPageButton.IsEnabled = true; } else if (offset == count) { LastPageButton.IsEnabled = true; NextPageButton.IsEnabled = false; } else { LastPageButton.IsEnabled = true; NextPageButton.IsEnabled = true; } SearchPageCount = count; PlayListDisplay.ItemsSource = pic.DefaultView; LodingImage.Visibility = Visibility.Hidden; })); }
private void DownLoadMusic(NetMusic netMusic) { var music = NetMusicHelper.GetMusicByNetMusic(netMusic); if (music == null) { return; } Dispatcher.Invoke(new Action(() => { if (!ParentWindow.LocalMusic.FolderList.Contains(Path.GetDirectoryName(music.Path) + "\\")) { ParentWindow.LocalMusic.FolderList.Add(Path.GetDirectoryName(music.Path) + "\\"); } ParentWindow.LocalMusic.LocalMusicList.Add(music); DownLoadedList.Add(music); netMusic.IsDownLoading = false; netMusic.IsDownLoaded = true; DownLoadingList.Remove(netMusic); })); }
private void GetPlayListItems(string url, NetMusicType pageType) { Dispatcher.Invoke(new Action(() => { LodingImage.Visibility = Visibility.Visible; })); var list = NetMusicHelper.GetPlayListItems(url, PageType); Dispatcher.Invoke(new Action(() => { ButtonGroup.Visibility = Visibility.Hidden; LodingImage.Visibility = Visibility.Hidden; NetMusicDataGrid.DataContext = list; NetMusicDataGrid.Visibility = Visibility.Visible; PlayAllLocalButton.Visibility = Visibility.Visible; AllAddToCurrentListButton.Visibility = Visibility.Visible; AddToMyPlayListButton.Visibility = Visibility.Visible; PlayListDisplay.Visibility = Visibility.Hidden; LastPageButton.Visibility = Visibility.Hidden; NextPageButton.Visibility = Visibility.Hidden; CloseDataGridButton.Visibility = Visibility.Visible; })); }
public void GetNetMusicList(string searchStr, int offset, NetMusicType netMusicType) { int count = 0; Dispatcher.Invoke(new Action(() => { LodingImage.Visibility = Visibility.Visible; CountLabel.DataContext = $"搜索\"{searchStr}\""; })); var t = NetMusicHelper.GetNetMusicList(searchStr, offset, netMusicType, out count); Dispatcher.Invoke(new Action(() => { MusicList.Clear(); MusicList = t; NetMusicDataGrid.DataContext = MusicList; })); Dispatcher.Invoke(new Action(() => { CountLabel.DataContext = $"搜索\"{searchStr}\", 找到 {count} 首单曲"; LodingImage.Visibility = Visibility.Hidden; })); }
private void AddNewPlayList(string url) { string name = string.Empty, imgurl = string.Empty; NetMusicType type; if (url.Contains("music.163.com")) { type = NetMusicType.CloudMusic; } else if (url.Contains("y.qq.com")) { type = NetMusicType.QQMusic; } else if (url.Contains("xiami.com")) { type = NetMusicType.XiaMiMusic; } else { return; } var nlist = NetMusicHelper.GetPlayListItems(url, type, out name, out imgurl); ObservableCollection <Music> mlist = new ObservableCollection <Music>(); foreach (var item in nlist) { mlist.Add(new Music(item)); } if (mlist.Count > 0) { Dispatcher.Invoke(new Action(() => { PlayListCollection.Add(new PlayListCollectionModel(name, imgurl, mlist)); })); } }
public void GetNetMusicList(RankingListType listType, NetMusicType netMusicType) { Dispatcher.Invoke(new Action(() => { LodingImage.Visibility = Visibility.Visible; })); var t = NetMusicHelper.GetNetMusicList(listType, netMusicType); Dispatcher.Invoke(new Action(() => { NetMusicList.Clear(); })); foreach (var item in t) { Dispatcher.Invoke(new Action(() => { NetMusicList.Add(item); })); } Dispatcher.Invoke(new Action(() => { LodingImage.Visibility = Visibility.Hidden; })); }
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 }); } })); }
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); }