Skip to content

Commit eb26407

Browse files
committed
support three decimal second
1 parent 4b4405b commit eb26407

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ ap.init();
8181

8282
#### LRC format:
8383

84+
Support multiple time tag, support three decimal second
85+
8486
```
8587
[mm:ss.xx]lyric
86-
[mm:ss.xx]lyric
88+
[mm:ss.xxx]lyric
8789
[mm:ss.xx][mm:ss.xx][mm:ss.xx]lyric
8890
...
8991
```

dist/APlayer.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/APlayer.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,11 @@ APlayer.prototype.secondToTime = function (second) {
337337
/**
338338
* Parse lrc, suppose multiple time tag
339339
*
340-
* @param {String} text - Format: [mm:ss.xx][mm:ss.xx]lyric
340+
* @param {String} text - Format:
341+
* [mm:ss.xx]lyric
342+
* [mm:ss.xxx]lyric
343+
* [mm:ss.xx][mm:ss.xx][mm:ss.xx]lyric
344+
*
341345
* @return {Array} [[time, text], [time, text], [time, text], ...]
342346
*/
343347
APlayer.prototype.parseLrc = function (text) {
@@ -346,16 +350,16 @@ APlayer.prototype.parseLrc = function (text) {
346350
var lyricLen = lyric.length;
347351
for (var i = 0; i < lyricLen; i++) {
348352
// match lrc time
349-
var lrcTimes = lyric[i].match(/\[(\d{2}):(\d{2})\.(\d{2})]/g);
353+
var lrcTimes = lyric[i].match(/\[(\d{2}):(\d{2})\.(\d{2,3})]/g);
350354
// match lrc text
351-
var lrcText = lyric[i].replace(/\[(\d{2}):(\d{2})\.(\d{2})]/g, '').replace(/^\s+|\s+$/g, '');
355+
var lrcText = lyric[i].replace(/\[(\d{2}):(\d{2})\.(\d{2,3})]/g, '').replace(/^\s+|\s+$/g, '');
352356

353357
if (lrcTimes != null) {
354358
// handle multiple time tag
355359
var timeLen = lrcTimes.length;
356360
for (var j = 0; j < timeLen; j++) {
357-
var oneTime = /\[(\d{2}):(\d{2})\.(\d{2})]/.exec(lrcTimes[j]);
358-
var lrcTime = (oneTime[1]) * 60 + parseInt(oneTime[2]) + parseInt(oneTime[3]) / 100;
361+
var oneTime = /\[(\d{2}):(\d{2})\.(\d{2,3})]/.exec(lrcTimes[j]);
362+
var lrcTime = (oneTime[1]) * 60 + parseInt(oneTime[2]) + parseInt(oneTime[3]) / ((oneTime[3] + '').length === 2 ? 100 : 1000);
359363
lrc.push([lrcTime, lrcText]);
360364
}
361365
}

0 commit comments

Comments
 (0)