/// <summary> /// 显示歌词 /// </summary> /// <param name="lrcPath">歌词文件路径</param> /// <param name="arrLrc">歌词数组</param> /// <param name="strTime">歌曲中的时间字符 MedioPlay.Ctlcontrols.currentPositionString</param> /// <param name="labFirst">显示的第一行文本</param> /// <param name="labNext">显示的下一行文本</param> /// <param name="musicName">歌曲名称</param> public static void ShowLrcMusic(string musicName, string lrcPath, string[] arrLrc, string strTime, Label labFirst, Label labNext) { if (!File.Exists(lrcPath)) return; else { //实例化个歌词集合 List<string> lrcList = new List<string>(); //一行一行读取歌词 arrLrc = File.ReadAllLines(lrcPath); //创建分割后的数组 string[] arr; for (int i = 0; i < arrLrc.Length; i++) { //按‘[]’,‘[]’分割 arr = arrLrc[i].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < arr.Length; j++) { //查处分割出的时间兵用‘|’隔开 if (arr[j].Contains(":") && arr[j].Contains(".")) //添加到集合中去 lrcList.Add(arr[j] + "|" + arr[arr.Length- 1]); } } //按时间从小到大排序 lrcList.Sort(); //排序后的集合赋给数组 arrLrc = lrcList.ToArray(); for (int i = 0; i < arrLrc.Length- 1; i++) { //比较字符串大小 if (string.Compare(strTime, arrLrc[0]) < 0) { labFirst.Text = musicName; labNext.Text = "。。。。。。。。。。。。。。。"; } if (string.Compare(strTime, arrLrc[i]) > 0 && string.Compare(strTime, arrLrc[i + 1]) < 0 ) { //得到歌词 labFirst.Text = arrLrc[i].Split('|')[1]; //得到下一句歌词 labNext.Text = arrLrc[i + 1].Split('|')[1]; } if (string.Compare(strTime, arrLrc[arrLrc.Length- 1]) > 0) { labFirst.Text = arrLrc[i + 1].Split('|')[1]; labNext.Text = arrLrc[i + 1].Split('|')[1]; } } } }