diff --git a/src/index.js b/src/index.js index 78a56cd1..9d3c8cff 100644 --- a/src/index.js +++ b/src/index.js @@ -694,7 +694,11 @@ export default class ReactJkMusicPlayer extends PureComponent { {audioLyricVisible && (
- {currentLyric || locale.emptyLyricText} + {this.state.lyric + ? (currentLyric || '') + .split('\n') + .map((s) =>
{s}
) + : locale.emptyLyricText}
)} diff --git a/src/lyric.js b/src/lyric.js index 865ac22a..22c80ae0 100644 --- a/src/lyric.js +++ b/src/lyric.js @@ -43,6 +43,7 @@ export default class Lyric { _initLines() { const lines = this.lrc.split('\n') const offset = parseInt(this.tags.offset, 10) || 0 + let lineCount = 0 for (let i = 0; i < lines.length; i++) { const line = lines[i] const result = timeExp.exec(line) @@ -56,14 +57,26 @@ export default class Lyric { (result[3] || 0) * 10 + offset, txt, + num: lineCount++, }) } } } this.lines.sort((a, b) => { - return a.time - b.time + const cp = a.time - b.time + if (cp === 0.0) { + return a.num - b.num + } + return cp }) + + for (let i = this.lines.length - 2; i >= 0; i--) { + if (this.lines[i].time === this.lines[i + 1].time) { + this.lines[i].txt += `\n${this.lines[i + 1].txt}` + this.lines.splice(i + 1, 1) + } + } } _findCurNum(time) {