Пример #1
0
        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
                    });
                }
            }));
        }