default options
This commit is contained in:
parent
7cb233e44c
commit
eeef9b400c
27
README.md
27
README.md
|
|
@ -24,7 +24,7 @@ npm install aplayer
|
|||
|
||||
## Usage
|
||||
|
||||
### The following HTML structure is used for APlayer:
|
||||
### HTML:
|
||||
|
||||
```
|
||||
<link rel="stylesheet" href="APlayer.css">
|
||||
|
|
@ -36,7 +36,7 @@ npm install aplayer
|
|||
<script src="APlayer.js"></script>
|
||||
```
|
||||
|
||||
### And this is how the APlayer is initialized:
|
||||
### JS:
|
||||
|
||||
```
|
||||
var ap = new APlayer({
|
||||
|
|
@ -54,6 +54,23 @@ var ap = new APlayer({
|
|||
ap.init();
|
||||
```
|
||||
|
||||
### JS Initialized Options
|
||||
|
||||
```
|
||||
{
|
||||
element: document.getElementById('player1'), // Optional, player element
|
||||
narrow: false, // Optional, narrow style
|
||||
autoplay: true, // Optional, autoplay
|
||||
showlrc: false, // Optional, show lrc
|
||||
music: { // Required, musci info
|
||||
title: 'Preparation', // Required, music title
|
||||
author: 'Hans Zimmer/Richard Harvey', // Required, music author
|
||||
url: 'http://7xifn9.com1.z0.glb.clouddn.com/Preparation.mp3', // Required, music url
|
||||
pic: 'http://7xifn9.com1.z0.glb.clouddn.com/Preparation.jpg' // Required, music picture
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### With lrc
|
||||
|
||||
Using [LRC format](https://en.wikipedia.org/wiki/LRC_(file_format))
|
||||
|
|
@ -87,10 +104,11 @@ HTML:
|
|||
|
||||
JS:
|
||||
|
||||
Init Option: `showlrc: false`
|
||||
Initialized Option: `showlrc: false`
|
||||
|
||||
### API
|
||||
|
||||
+ `ap.init()`
|
||||
+ `ap.play()`
|
||||
+ `ap.pause()`
|
||||
|
||||
|
|
@ -107,9 +125,10 @@ gulp
|
|||
- [x] 分享到微博
|
||||
- [x] 加载样式及错误处理
|
||||
- [x] 窄样式 及 移动版样式
|
||||
- [x] 歌词展示
|
||||
- [x] 默认选项
|
||||
- [ ] 移动端兼容性
|
||||
- [ ] 播放列表
|
||||
- [ ] 歌词展示
|
||||
- [ ] 宽度高度自定义
|
||||
|
||||
## Issues
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@
|
|||
element: document.getElementById('player1'),
|
||||
narrow: false,
|
||||
autoplay: false,
|
||||
showlrc: false,
|
||||
music: {
|
||||
title: 'Preparation',
|
||||
author: 'Hans Zimmer/Richard Harvey',
|
||||
|
|
@ -149,6 +150,7 @@
|
|||
element: document.getElementById('player2'),
|
||||
narrow: true,
|
||||
autoplay: false,
|
||||
showlrc: false,
|
||||
music: {
|
||||
title: 'Preparation',
|
||||
author: 'Hans Zimmer/Richard Harvey',
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -17,10 +17,12 @@ gulp.task('browser-sync', function() {
|
|||
});
|
||||
});
|
||||
|
||||
// Move font files
|
||||
// Move files
|
||||
gulp.task('copy', function () {
|
||||
return gulp.src('src/font/*')
|
||||
gulp.src('src/font/*')
|
||||
.pipe(gulp.dest('dist/font'));
|
||||
gulp.src('src/*.jpg')
|
||||
.pipe(gulp.dest('dist'));
|
||||
});
|
||||
|
||||
// Build js files
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "aplayer",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.2",
|
||||
"description": "Wow, such a beautiful html5 music player",
|
||||
"main": "APlayer.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,25 @@
|
|||
function APlayer(option) {
|
||||
// handle options error
|
||||
if (!('music' in option && 'title' in option.music && 'author' in option.music && 'url' in option.music && 'pic' in option.music)) {
|
||||
throw 'APlayer Error: Music, music.title, music.author, music.url, music.pic are required in options';
|
||||
}
|
||||
if (option.element === null) {
|
||||
throw 'APlayer Error: element option null';
|
||||
}
|
||||
|
||||
// default options
|
||||
var defaultOption = {
|
||||
element: document.getElementsByClassName('aplayer')[0],
|
||||
narrow: false,
|
||||
autoplay: false,
|
||||
showlrc: false
|
||||
};
|
||||
for (var defaultKey in defaultOption) {
|
||||
if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
|
||||
option[defaultKey] = defaultOption[defaultKey];
|
||||
}
|
||||
}
|
||||
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
|
|
@ -8,11 +29,10 @@ APlayer.prototype.init = function () {
|
|||
|
||||
// parser lrc
|
||||
if (this.option.showlrc) {
|
||||
var lines = [];
|
||||
this.lrcTime = [];
|
||||
this.lrcLine = [];
|
||||
var lrcs = this.element.getElementsByClassName('aplayer-lrc-content')[0].innerHTML;
|
||||
lines = lrcs.split(/\n/);
|
||||
var lines = lrcs.split(/\n/);
|
||||
var timeExp = /\[(\d{2})\:(\d{2})\.(\d{2})\]/;
|
||||
var lrcExp = /](.*)$/;
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
|
|
@ -109,6 +129,7 @@ APlayer.prototype.init = function () {
|
|||
}, 500);
|
||||
});
|
||||
|
||||
// audio download error
|
||||
this.audio.addEventListener('error', function () {
|
||||
_self.element.getElementsByClassName('aplayer-author')[0].innerHTML = ' - ' + '加载失败 ╥﹏╥';
|
||||
});
|
||||
|
|
|
|||
|
|
@ -187,15 +187,6 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||
font-size: 12px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
a {
|
||||
margin-right: 7px;
|
||||
font-size: 14px;
|
||||
color: #000;
|
||||
&:hover {
|
||||
color: #E90F24;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-controller {
|
||||
|
|
|
|||
Loading…
Reference in New Issue