Bug报告以及解决方法: U_Main.pas单元中的TDisPlay.readfile过程中,看下面的代码:
begin sj := copy(temp, pos('[', temp) + 1, pos(']', temp) - pos('[', temp) - 1); temp := copy(temp, pos(']', temp) + 1, length(temp) - pos(']', temp)); if strisint(copy(sj, 1, 2)) and strisint(copy(sj, 4, 2)) then begin sj := inttostr(( strtoint(copy(sj, 1, 2)) * 60 * 1000 + //{歌词时间 [16.29.074] 中的16} strtoint(copy(sj, 4, 2)) * 1000 + // { [16.29.074] 中的29} strtoint(copy(sj, 7, 2)) * 10 // { [16.29.074] 中的074 如果是这样的时间格式 [00:17] 这样的就要出错} ) - offset); sj := format('%10s', [sj]); tmp.Add(sj); end; y := pos('[', temp); end;
代码修改为: 增加一个字符串变量ss,
begin sj := copy(temp, pos('[', temp) + 1, pos(']', temp) - pos('[', temp) - 1); //取出类似[16:29.074]中的时间 temp := copy(temp, pos(']', temp) + 1, length(temp) - pos(']', temp)); //取出歌词 if strisint(copy(sj, 1, 2)) and strisint(copy(sj, 4, 2)) then begin ss:=sj; sj := inttostr(( strtoint(copy(sj, 1, 2)) * 60 * 1000 + strtoint(copy(sj, 4, 2)) * 1000 ) - offset); if strisint(copy(ss, 7, 2)) then sj:= inttostr(( strtoint(copy(ss, 7, 2)) * 10)+strtoint(sj)); sj := format('%10s', [sj]); tmp.Add(sj); end; y := pos('[', temp); end;
另外,如果歌词文件有问题,比如少一个“[”或“]”则程序就会死循环,耗尽cpu,直至当机。 加两个歌词文件的完整校验函数,主要是判断是不是缺少“[”或“]”。
//////////自编某一字符串中两个子字符串出现的次数是否相等的函数(判断[ ] 是否个数一样) function CheckStrTotal(S, string1, string2: string): Boolean; var str1, str2: string; i, j, nb1, nb2, StrLen: integer; begin str1 := S; str2 := S; nb1 := 0; nb2 := 0;
i := pos(string1, str1); while i <> 0 do begin i := pos(string1, str1); if i > 0 then begin StrLen := length(string1); delete(str1, i, StrLen); nb1 := nb1 + 1; end; end;
j := pos(string2, str2); while j <> 0 do begin j := pos(string2, str2); if j > 0 then begin StrLen := length(string2); delete(str2, j, StrLen); nb2 := nb2 + 1; end; end;
if nb1 = nb2 then Result := True else Result := false; end;
//////////检查lrc文件的完整性, 防止死循环////////// function CheckLrcFile(LrcfileStr: string): Boolean; var strlist: tstringlist; str1, str2: string; i, j, mm, nn: integer; begin try strlist := tstringlist.Create; strlist.LoadFromFile(LrcfileStr); for i := 0 to strlist.Count - 1 do begin if CheckStrTotal(strlist[i], '[', ']') then Result := True else begin Result := false; break; end; end; finally strlist.Free; end; end;
其中CheckLrcFile函数在Readfile之前加入。 |