Beispiel #1
0
        async void UpDateSong()
        {
            _albumRoot               = PlayingService.PlayingAlbum;
            _songsItem               = PlayingService.PlayingSong;
            Image_album.Source       = PlayingService.PlayingAlbumBitmapImage;
            Button_albumName.Content = _albumRoot.album.name;
            string name = "";

            for (int i = 0; i < _songsItem.ar.Count; i++)
            {
                if (i != 0)
                {
                    name += "/";
                }
                name += _songsItem.ar[i].name;
            }
            ListBox_artists.ItemsSource = _songsItem.ar;
            Button_artistName.Content   = name;
            TextBlock_songName.Text     = _songsItem.Name;
            LyricRoot lyricRoot = await Task.Run(() => LyricService.GetLyric(_songsItem.Id));

            if (lyricRoot == null)
            {
                ListBox_lyric.ItemsSource = null;
                return;
            }
            lyricStrs = LyricService.GetLyricStrs(lyricRoot);
            if (lyricStrs != null)
            {
                if (lyricStrs.Count == 0)
                {
                    DateTime dateTime = DateTime.Now;
                    lyricStrs.Add(new LyricStr()
                    {
                        DateTime = dateTime, Original = "无歌词"
                    });
                }
                ListBox_lyric.ItemsSource = lyricStrs;
                ListBox_lyric.ScrollIntoView(lyricStrs.First());
            }
            UpDateComment();
            UpDateSimiSongs();
        }
Beispiel #2
0
        /// <summary>
        /// 分析提取歌词
        /// </summary>
        /// <param name="lyricRoot">原始获得的歌词实例</param>
        /// <returns>用于滚动显示的歌词</returns>
        public static List <LyricStr> GetLyricStrs(LyricRoot lyricRoot)
        {
            List <LyricStr> lyricStrs = new List <LyricStr>();

            if (lyricRoot.lrc != null && lyricRoot.lrc.lyric != null)//原歌词
            {
                var array = lyricRoot.lrc.lyric.Split("\n");
                foreach (var temp in array)
                {
                    var array2 = temp.Split(new char[2] {
                        '[', ']'
                    });
                    if (array2.Length != 3)
                    {
                        continue;
                    }
                    var array3 = array2[1].Split(new char[2] {
                        ':', '.'
                    });
                    if (array3.Length != 3)
                    {
                        continue;
                    }
                    DateTime dateTime = new DateTime();
                    try
                    {
                        dateTime = dateTime.AddMinutes(double.Parse(array3[0]));
                        dateTime = dateTime.AddSeconds(double.Parse(array3[1]));
                        dateTime = dateTime.AddMilliseconds(double.Parse(array3[2]));
                        lyricStrs.Add(new LyricStr()
                        {
                            DateTime = dateTime, Original = array2[2]
                        });
                    }
                    catch (Exception) { }
                }
            }
            if (lyricRoot.tlyric != null && lyricRoot.tlyric.lyric != null)//翻译歌词
            {
                var array = lyricRoot.tlyric.lyric.Split("\n");
                foreach (var temp in array)
                {
                    var array2 = temp.Split(new char[2] {
                        '[', ']'
                    });
                    if (array2.Length != 3)
                    {
                        continue;
                    }
                    var array3 = array2[1].Split(new char[2] {
                        ':', '.'
                    });
                    if (array3.Length != 3)
                    {
                        continue;
                    }
                    DateTime dateTime = new DateTime();
                    try
                    {
                        dateTime = dateTime.AddMinutes(double.Parse(array3[0]));
                        dateTime = dateTime.AddSeconds(double.Parse(array3[1]));
                        dateTime = dateTime.AddMilliseconds(double.Parse(array3[2]));
                        var found = lyricStrs.Find(p => p.DateTime.TimeOfDay == dateTime.TimeOfDay);
                        if (found != null)
                        {
                            found.Tran = array2[2];
                        }
                        else
                        {
                            lyricStrs.Add(new LyricStr()
                            {
                                DateTime = dateTime, Original = array2[2]
                            });
                        }
                    }
                    catch (Exception) { }
                }
            }

            return(lyricStrs);
        }