From 128039d67857b900cfa911c929c4a0e8b0df1d00 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 9 Apr 2022 13:42:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AD=8C=E8=AF=8D=E5=81=8F?= =?UTF-8?q?=E7=A7=BB=E5=A4=84=E7=90=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/utils/compositions/useLyric.js | 4 +++- src/renderer/utils/lyric-font-player/index.js | 23 +++++++++---------- .../utils/lyric-font-player/line-player.js | 5 +--- 3 files changed, 15 insertions(+), 17 deletions(-) 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() {