Skip to content

Commit 9080b73

Browse files
committed
handle lrc format error
1 parent f2ece03 commit 9080b73

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,16 @@ ap.init();
7979

8080
### With lrc
8181

82-
Using [LRC format](https://en.wikipedia.org/wiki/LRC_(file_format))
82+
#### LRC format:
8383

84-
HTML:
84+
```
85+
[mm:ss.xx]lyric
86+
[mm:ss.xx]lyric
87+
[mm:ss.xx]lyric
88+
...
89+
```
90+
91+
#### HTML:
8592

8693
```HTML
8794
<link rel="stylesheet" href="APlayer.min.css">
@@ -107,7 +114,7 @@ HTML:
107114
<script src="APlayer.min.js"></script>
108115
```
109116

110-
JS:
117+
#### JS:
111118

112119
Option: `showlrc: false`
113120

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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aplayer",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "Wow, such a beautiful html5 music player",
55
"main": "APlayer.js",
66
"scripts": {

src/APlayer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ APlayer.prototype.init = function () {
4141
var lines = lrcs.split(/\n/);
4242
var timeExp = /\[(\d{2}):(\d{2})\.(\d{2})]/;
4343
var lrcExp = /](.*)$/;
44+
var notLrcLineExp = /\[[A-Za-z]+:/;
4445
for (var i = 0; i < lines.length; i++) {
46+
lines[i] = lines[i].replace(/^\s+|\s+$/g, '');
4547
var oneTime = timeExp.exec(lines[i]);
4648
var oneLrc = lrcExp.exec(lines[i]);
47-
if (oneTime && oneLrc) {
49+
if (oneTime && oneLrc && !lrcExp.exec(oneLrc[1])) {
4850
this.lrcTime.push(parseInt(oneTime[1]) * 60 + parseInt(oneTime[2]) + parseInt(oneTime[3]) / 100);
4951
this.lrcLine.push(oneLrc[1]);
5052
}
53+
else if (lines[i] && !notLrcLineExp.exec(lines[i])) {
54+
throw 'APlayer Error: lrc format error : should be like `[mm:ss.xx]lyric` : ' + lines[i];
55+
}
5156
}
5257
}
5358

0 commit comments

Comments
 (0)