新增播放速率调整功能
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user