From 3822b498a16dbfe85c6c5dd74a112d6f50765fb6 Mon Sep 17 00:00:00 2001 From: qier222 Date: Fri, 15 Jan 2021 16:45:07 +0800 Subject: [PATCH] fix: lyrics issues --- src/utils/lyrics.js | 5 +++-- src/views/lyrics.vue | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/utils/lyrics.js b/src/utils/lyrics.js index c68bb42..01e00fd 100644 --- a/src/utils/lyrics.js +++ b/src/utils/lyrics.js @@ -22,9 +22,10 @@ export function parseLyric(lrc) { const t = timeRegExpArr[k]; const min = Number(String(t.match(/\[\d*/i)).slice(1)); const sec = Number(String(t.match(/:\d*/i)).slice(1)); - const time = min * 60 + sec; + const ms = Number(t.match(/\d*\]/i)[0].slice(0, 2)) / 100; + const time = min * 60 + sec + ms; if (content !== "") { - lrcObj.push({ time: time, content }); + lrcObj.push({ time: time, rawTime: timeRegExpArr[0], content }); } } } diff --git a/src/views/lyrics.vue b/src/views/lyrics.vue index 42732e4..29ea834 100644 --- a/src/views/lyrics.vue +++ b/src/views/lyrics.vue @@ -163,7 +163,7 @@ export default { lyricsInterval: null, lyric: [], tlyric: [], - highlightLyricIndex: 0, + highlightLyricIndex: -1, minimize: true, }; }, @@ -195,10 +195,10 @@ export default { // content统一转换数组形式 if (lyricFiltered.length) { lyricFiltered.forEach((l) => { - const { time, content } = l; + const { rawTime, time, content } = l; const lyricItem = { time, content, contents: [content] }; const sameTimeTLyric = this.tlyric.find( - ({ time: tLyricTime }) => tLyricTime === time + ({ rawTime: tLyricRawTime }) => tLyricRawTime === rawTime ); if (sameTimeTLyric) { const { content: tLyricContent } = sameTimeTLyric; @@ -267,12 +267,12 @@ export default { }, setLyricsInterval() { this.lyricsInterval = setInterval(() => { + const progress = this.player.seek() ?? 0; let oldHighlightLyricIndex = this.highlightLyricIndex; this.highlightLyricIndex = this.lyric.findIndex((l, index) => { const nextLyric = this.lyric[index + 1]; return ( - this.progress >= l.time && - (nextLyric ? this.progress < nextLyric.time : true) + progress >= l.time && (nextLyric ? progress < nextLyric.time : true) ); }); if (oldHighlightLyricIndex !== this.highlightLyricIndex) { @@ -283,7 +283,7 @@ export default { block: "center", }); } - }, 500); + }, 50); }, formatLine(line) { const showLyricsTranslation = this.$store.state.settings