通过歌词调整进度时添加对偏移时间的计算

pull/930/merge
lyswhut 2022-03-23 17:49:34 +08:00
parent e0e65e4374
commit 469832a598
4 changed files with 12 additions and 7 deletions

View File

@ -4,7 +4,8 @@ export const lyric = reactive({
lines: [],
text: '',
line: 0,
offset: 0, // 临时延迟
offset: 0, // 歌词延迟
tempOffset: 0, // 歌词临时延迟
})
export const setLines = lines => {
@ -17,3 +18,6 @@ export const setText = (text, line) => {
export const setOffset = offset => {
lyric.offset = offset
}
export const setTempOffset = offset => {
lyric.tempOffset = offset
}

View File

@ -3,7 +3,7 @@ import Lyric from '@renderer/utils/lyric-font-player'
import { getCurrentTime as getPlayerCurrentTime } from '@renderer/plugins/player'
import { setDesktopLyricInfo, onGetDesktopLyricInfo } from '@renderer/utils/tools'
import { player as eventPlayerNames } from '@renderer/event/names'
import { lyric, setText, setLines, setOffset } from '@renderer/core/share/lyric'
import { lyric, setText, setLines, setOffset, setTempOffset } from '@renderer/core/share/lyric'
import { musicInfo, setStatusText, isPlay, playMusicInfo } from '@renderer/core/share/player'
export default ({ setting }) => {
@ -17,11 +17,12 @@ export default ({ setting }) => {
setStatusText(text)
// console.log(line, text)
},
onSetLyric(lines) { // listening lyrics seting event
onSetLyric(lines, offset) { // listening lyrics seting event
// console.log(lines) // lines is array of all lyric text
setLines(markRawList([...lines]))
setText(lines[0] ?? '', 0)
setOffset(0) // 重置临时延迟
setOffset(offset) // 歌词延迟
setTempOffset(0) // 重置临时延迟
},
// offset: 80,
})
@ -58,7 +59,7 @@ export default ({ setting }) => {
}
const setLyricOffset = offset => {
setOffset(offset)
setTempOffset(offset)
if (isPlay.value && (musicInfo.url || playMusicInfo.listId == 'download')) {
setTimeout(() => {
const time = getCurrentTime()

View File

@ -28,7 +28,7 @@ export default ({ isPlay, lyric }) => {
if (time == -1) return
handleSkipMouseLeave()
isStopScroll.value = false
window.eventHub.emit(eventPlayerNames.setProgress, time)
window.eventHub.emit(eventPlayerNames.setProgress, Math.max(time + lyric.offset + lyric.tempOffset, 0))
if (!isPlay.value) window.eventHub.emit(eventPlayerNames.setPlay)
}
const handleSkipMouseEnter = () => {

View File

@ -34,7 +34,7 @@ module.exports = class LinePlayer {
if (this.translationLyric == null) this.translationLyric = ''
this._initTag()
this._initLines()
this.onSetLyric(this.lines)
this.onSetLyric(this.lines, this.tags.offset + this.offset)
}
_initTag() {