Skip to content

Commit

Permalink
trans -> translated
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorModi committed Feb 22, 2024
1 parent 8152d3a commit f375a60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/cn/zhaiyifan/lyric/LyricUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public static Lyric parseLyric(ILrcProvider.LyricResult lyricResult, ILrcProvide
BufferedReader tbr = new BufferedReader(new StringReader(lyricResult.mTranslatedLyric));
String transLine;
while ((transLine = tbr.readLine()) != null) {
if (!parseLine(lyric.transSentenceList, transLine, lyric)) return null;
if (!parseLine(lyric.translatedSentenceList, transLine, lyric)) return null;
}
lyric.transSentenceList.sort(new Lyric.SentenceComparator());
lyric.translatedSentenceList.sort(new Lyric.SentenceComparator());
} catch (IOException e) {
e.fillInStackTrace();
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/cn/zhaiyifan/lyric/model/Lyric.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Lyric {
public int offset; // 偏移值
public long length; // 歌曲长度
public List<Sentence> sentenceList = new ArrayList<Sentence>(100);
public List<Sentence> transSentenceList = new ArrayList<Sentence>(100);
public List<Sentence> translatedSentenceList = new ArrayList<Sentence>(100);

@NotNull
public String toString() {
Expand All @@ -34,9 +34,9 @@ public String toString() {
stringBuilder.append(sentence.toString()).append("\n");
}
}
if (transSentenceList != null) {
if (translatedSentenceList != null) {
stringBuilder.append ("--- Translate Lyrics ---\n");
for (Sentence sentence : transSentenceList) {
for (Sentence sentence : translatedSentenceList) {
stringBuilder.append(sentence.toString()).append("\n");
}
}
Expand Down Expand Up @@ -68,4 +68,4 @@ public String toString() {
return fromTime + ": " + content;
}
}
}
}
19 changes: 7 additions & 12 deletions app/src/main/java/statusbar/finder/MusicListenerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,21 +365,16 @@ private void updateLyric(long position) {
}
}

private int calculateDelay(long position) { // 计算Delay
int delay = 0;
int nextFound = LyricUtils.getSentenceIndex(mLyric.sentenceList, position, 0, mLyric.offset) + 1; // 获取下一句歌词的 Sentence

if (nextFound < mLyric.sentenceList.size()) { //判断是否超出范围 防止崩溃
Lyric.Sentence nextSentence = mLyric.sentenceList.get(nextFound);
delay = (int) (nextSentence.fromTime - position) / 1000 / 3;
}

return delay;
private int calculateDelay(long position) {
int nextFoundIndex = LyricUtils.getSentenceIndex(mLyric.sentenceList, position, 0, mLyric.offset) + 1;
return nextFoundIndex >= mLyric.sentenceList.size() ? 0 :
(int) (mLyric.sentenceList.get(nextFoundIndex)
.fromTime - position / 1000) / 3;
}

private Lyric.Sentence getTranslatedSentence(long position) { // 获取翻译歌词
if (!mLyric.transSentenceList.isEmpty()) {
return LyricUtils.getSentence(mLyric.transSentenceList, position, 0, mLyric.offset);
if (!mLyric.translatedSentenceList.isEmpty()) {
return LyricUtils.getSentence(mLyric.translatedSentenceList, position, 0, mLyric.offset);
}
return null;
}
Expand Down

0 comments on commit f375a60

Please sign in to comment.