修复歌词偏移处理问题

pull/930/merge
lyswhut 2022-04-09 13:42:12 +08:00
parent bb5de056d4
commit 128039d678
3 changed files with 15 additions and 17 deletions

View File

@ -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 = () => {

View File

@ -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
}
}

View File

@ -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() {