handle lrc format error
This commit is contained in:
@@ -79,9 +79,16 @@ ap.init();
|
||||
|
||||
### With lrc
|
||||
|
||||
Using [LRC format](https://en.wikipedia.org/wiki/LRC_(file_format))
|
||||
#### LRC format:
|
||||
|
||||
HTML:
|
||||
```
|
||||
[mm:ss.xx]lyric
|
||||
[mm:ss.xx]lyric
|
||||
[mm:ss.xx]lyric
|
||||
...
|
||||
```
|
||||
|
||||
#### HTML:
|
||||
|
||||
```HTML
|
||||
<link rel="stylesheet" href="APlayer.min.css">
|
||||
@@ -107,7 +114,7 @@ HTML:
|
||||
<script src="APlayer.min.js"></script>
|
||||
```
|
||||
|
||||
JS:
|
||||
#### JS:
|
||||
|
||||
Option: `showlrc: false`
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "aplayer",
|
||||
"version": "1.2.2",
|
||||
"version": "1.2.3",
|
||||
"description": "Wow, such a beautiful html5 music player",
|
||||
"main": "APlayer.js",
|
||||
"scripts": {
|
||||
|
||||
+6
-1
@@ -41,13 +41,18 @@ APlayer.prototype.init = function () {
|
||||
var lines = lrcs.split(/\n/);
|
||||
var timeExp = /\[(\d{2}):(\d{2})\.(\d{2})]/;
|
||||
var lrcExp = /](.*)$/;
|
||||
var notLrcLineExp = /\[[A-Za-z]+:/;
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
lines[i] = lines[i].replace(/^\s+|\s+$/g, '');
|
||||
var oneTime = timeExp.exec(lines[i]);
|
||||
var oneLrc = lrcExp.exec(lines[i]);
|
||||
if (oneTime && oneLrc) {
|
||||
if (oneTime && oneLrc && !lrcExp.exec(oneLrc[1])) {
|
||||
this.lrcTime.push(parseInt(oneTime[1]) * 60 + parseInt(oneTime[2]) + parseInt(oneTime[3]) / 100);
|
||||
this.lrcLine.push(oneLrc[1]);
|
||||
}
|
||||
else if (lines[i] && !notLrcLineExp.exec(lines[i])) {
|
||||
throw 'APlayer Error: lrc format error : should be like `[mm:ss.xx]lyric` : ' + lines[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user