From 10700030f94040f541767ed85abf68a38e879593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Coelho?= <1120458@isep.ipp.pt> Date: Wed, 8 Mar 2023 01:52:15 +0000 Subject: [PATCH] fix: lyrics overlap --- src/index.js | 7 +++++-- src/lyric.js | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 78a56cd1..ef6272e4 100644 --- a/src/index.js +++ b/src/index.js @@ -1338,8 +1338,8 @@ export default class ReactJkMusicPlayer extends PureComponent { onAudioPause = () => { this.setState({ playing: false }) this.props.onAudioPause && this.props.onAudioPause(this.getBaseAudioInfo()) - if (this.state.lyric && this.lyric) { - this.lyric.togglePlay() + if (this.lyric) { + this.lyric.pause() } } @@ -1546,6 +1546,8 @@ export default class ReactJkMusicPlayer extends PureComponent { const { restartCurrentOnPrev } = this.props if (restartCurrentOnPrev && this.audio.currentTime > 1) { this.audio.currentTime = 0 + this.initLyricParser() + this.lyric.seek(0) return } @@ -1981,6 +1983,7 @@ export default class ReactJkMusicPlayer extends PureComponent { } initLyricParser = () => { + this.removeLyric() this.lyric = new Lyric(this.state.lyric, this.onLyricChange) this.setState({ currentLyric: this.lyric.lines[0] && this.lyric.lines[0].text, diff --git a/src/lyric.js b/src/lyric.js index 865ac22a..139d417a 100644 --- a/src/lyric.js +++ b/src/lyric.js @@ -128,6 +128,14 @@ export default class Lyric { } } + pause() { + const now = +new Date() + if (this.state === STATE_PLAYING) { + this.stop() + this.pauseStamp = now + } + } + stop() { this.state = STATE_PAUSE clearTimeout(this.timer)