新增播放速率调整功能

This commit is contained in:
lyswhut
2023-02-08 18:27:35 +08:00
parent 9522e975a0
commit f809782559
27 changed files with 450 additions and 154 deletions
@@ -38,7 +38,7 @@ const parseExtendedLyric = (lrcLinesMap, extendedLyric) => {
}
module.exports = class LinePlayer {
constructor({ offset = 0, onPlay = function() { }, onSetLyric = function() { } } = {}) {
constructor({ offset = 0, rate = 1, onPlay = function() { }, onSetLyric = function() { } } = {}) {
this.tags = {}
this.lines = null
this.onPlay = onPlay
@@ -49,6 +49,7 @@ module.exports = class LinePlayer {
this.offset = offset
this._performanceTime = 0
this._startTime = 0
this._rate = rate
}
_init() {
@@ -119,7 +120,7 @@ module.exports = class LinePlayer {
}
_currentTime() {
return getNow() - this._performanceTime + this._startTime
return (getNow() - this._performanceTime) * this._rate + this._startTime
}
_findCurLineNum(curTime, startIndex = 0) {
@@ -146,14 +147,14 @@ module.exports = class LinePlayer {
if (driftTime >= 0 || this.curLineNum === 0) {
let nextLine = this.lines[this.curLineNum + 1]
this.delay = nextLine.time - curLine.time - driftTime
const delay = (nextLine.time - curLine.time - driftTime) / this._rate
if (this.delay > 0) {
if (delay > 0) {
if (this.isPlay) {
timeoutTools.start(() => {
if (!this.isPlay) return
this._refresh()
}, this.delay)
}, delay)
}
this.onPlay(this.curLineNum, curLine.text, currentTime)
return
@@ -195,6 +196,13 @@ module.exports = class LinePlayer {
}
}
setPlaybackRate(rate) {
this._rate = rate
if (!this.lines.length) return
if (!this.isPlay) return
this.play(this._currentTime())
}
setLyric(lyric, extendedLyrics) {
// console.log(extendedLyrics)
if (this.isPlay) this.pause()