修复一些潜在的错误

This commit is contained in:
lyswhut 2021-08-17 10:32:13 +08:00
parent 7742f23f6d
commit 0e1deed340
2 changed files with 9 additions and 8 deletions

View File

@ -89,7 +89,7 @@ public class Lyric extends LyricPlayer {
private void setViewLyric(int lineNum) {
lastLine = lineNum;
if (lyricView == null) return;
if (lineNum > lines.size() - 1) return;
if (lineNum < 0 || lineNum > lines.size() - 1) return;
HashMap line = (HashMap) lines.get(lineNum);
if (line == null) {
lyricView.setLyric("", "");
@ -138,7 +138,7 @@ public class Lyric extends LyricPlayer {
}
@Override
public void onPlay(int lineNum, String text) {
public void onPlay(int lineNum) {
setViewLyric(lineNum);
// Log.d("Lyric", lineNum + " " + text + " " + (String) line.get("translation"));
}

View File

@ -185,7 +185,7 @@ public class LyricPlayer {
int curLineNum = this.findCurLineNum(getCurrentTime());
if (this.curLineNum != curLineNum) {
this.curLineNum = curLineNum;
this.onPlay(curLineNum, (String) ((HashMap) lines.get(curLineNum)).get("text"));
this.onPlay(curLineNum);
}
}
@ -210,7 +210,7 @@ public class LyricPlayer {
}
private void handleMaxLine() {
this.onPlay(this.curLineNum, (String) lines.get(curLineNum).get("text"));
this.onPlay(this.curLineNum);
this.pause();
}
@ -219,17 +219,18 @@ public class LyricPlayer {
// Log.d("Lyric", "refresh: " + curLineNum);
curLineNum++;
if (curLineNum == maxLine) {
if (curLineNum >= maxLine) {
handleMaxLine();
return;
}
HashMap curLine = lines.get(curLineNum);
HashMap nextLine = lines.get(curLineNum + 1);
int currentTime = getCurrentTime();
int driftTime = currentTime - (int) curLine.get("time");
// Log.d("Lyric", "driftTime: " + driftTime);
if (driftTime >= 0 || curLineNum == 0) {
HashMap nextLine = lines.get(curLineNum + 1);
delay = (int) nextLine.get("time") - (int) curLine.get("time") - driftTime;
// Log.d("Lyric", "delay: " + delay + " driftTime: " + driftTime);
if (delay > 0) {
@ -246,7 +247,7 @@ public class LyricPlayer {
refresh();
}, delay);
}
onPlay(curLineNum, (String) curLine.get("text"));
onPlay(curLineNum);
return;
}
}
@ -262,7 +263,7 @@ public class LyricPlayer {
init();
}
public void onPlay(int lineNum, String text) {}
public void onPlay(int lineNum) {}
public void onSetLyric(List lines) {}