handle lrc format error

This commit is contained in:
DIYgod 2015-12-12 22:34:09 +08:00
parent f2ece03f2d
commit 9080b73297
4 changed files with 18 additions and 6 deletions

View File

@ -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`

2
dist/APlayer.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -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": {

View File

@ -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];
}
}
}