diff --git a/src/renderer/utils/compositions/useLyric.js b/src/renderer/utils/compositions/useLyric.js index b9819d84..5240e3b9 100644 --- a/src/renderer/utils/compositions/useLyric.js +++ b/src/renderer/utils/compositions/useLyric.js @@ -28,7 +28,9 @@ export default ({ isPlay, lyric, isShowLyricProgressSetting }) => { if (time == -1) return handleSkipMouseLeave() isStopScroll.value = false - window.eventHub.emit(eventPlayerNames.setProgress, Math.max(time + lyric.offset + lyric.tempOffset, 0)) + let offset = lyric.offset + lyric.tempOffset + if (offset) offset = offset / 1000 + window.eventHub.emit(eventPlayerNames.setProgress, Math.max(time + offset, 0)) if (!isPlay.value) window.eventHub.emit(eventPlayerNames.setPlay) } const handleSkipMouseEnter = () => { diff --git a/src/renderer/utils/lyric-font-player/index.js b/src/renderer/utils/lyric-font-player/index.js index 72a47b05..637f939c 100644 --- a/src/renderer/utils/lyric-font-player/index.js +++ b/src/renderer/utils/lyric-font-player/index.js @@ -34,23 +34,19 @@ module.exports = class Lyric { this.playingLineNum = -1 this.isLineMode = false + + this.linePlayer = new LinePlayer({ + offset: this.offset, + onPlay: this._handleLinePlayerOnPlay, + onSetLyric: this._handleLinePlayerOnSetLyric, + }) } _init() { this.playingLineNum = -1 this.isLineMode = false - if (this.linePlayer) { - this.linePlayer.setLyric(this.lyric, this.translationLyric) - } else { - this.linePlayer = new LinePlayer({ - lyric: this.lyric, - translationLyric: this.translationLyric, - offset: this.offset, - onPlay: this._handleLinePlayerOnPlay, - onSetLyric: this._handleLinePlayerOnSetLyric, - }) - } + this.linePlayer.setLyric(this.lyric, this.translationLyric) } _handleLinePlayerOnPlay = (num, text, curTime) => { @@ -148,6 +144,10 @@ module.exports = class Lyric { }) } + // 如果是逐行歌词,则添加 60ms 的偏移 + let newOffset = this.isLineMode ? this.offset + 60 : this.offset + offset = offset - this.linePlayer.offset + newOffset + this.linePlayer.offset = newOffset this.onSetLyric(this._lines, offset) } @@ -166,6 +166,5 @@ module.exports = class Lyric { this.lyric = lyric this.translationLyric = translationLyric this._init() - this.linePlayer.offset = this.isLineMode ? this.offset + 90 : this.offset } } diff --git a/src/renderer/utils/lyric-font-player/line-player.js b/src/renderer/utils/lyric-font-player/line-player.js index 40bb44f5..db9b62a8 100644 --- a/src/renderer/utils/lyric-font-player/line-player.js +++ b/src/renderer/utils/lyric-font-player/line-player.js @@ -12,9 +12,7 @@ const tagRegMap = { const timeoutTools = new TimeoutTools() module.exports = class LinePlayer { - constructor({ lyric = '', translationLyric = '', offset = 0, onPlay = function() { }, onSetLyric = function() { } } = {}) { - this.lyric = lyric - this.translationLyric = translationLyric + constructor({ offset = 0, onPlay = function() { }, onSetLyric = function() { } } = {}) { this.tags = {} this.lines = null this.translationLines = null @@ -26,7 +24,6 @@ module.exports = class LinePlayer { this.offset = offset this._performanceTime = 0 this._startTime = 0 - this._init() } _init() {