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)