Skip to content

Commit a966182

Browse files
committed
update readme
1 parent 5fe4310 commit a966182

File tree

1 file changed

+54
-67
lines changed

1 file changed

+54
-67
lines changed

README.md

Lines changed: 54 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
# React-APlayer [![GitHub tag](https://img.shields.io/github/tag/sabrinaluo/react-aplayer.svg)](https://github.com/sabrinaluo/react-aplayer/releases) [![npm](https://img.shields.io/npm/dm/react-aplayer.svg)](https://www.npmjs.com/package/react-aplayer) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/sabrinaluo/react-aplayer/blob/master/LICENSE)
2-
A React wrapper component of [APlayer](https://github.com/DIYgod/APlayer)
1+
2+
# React-APlayer
3+
[![GitHub tag](https://img.shields.io/github/tag/sabrinaluo/react-aplayer.svg)](https://github.com/sabrinaluo/react-aplayer/releases) [![npm](https://img.shields.io/npm/dm/react-aplayer.svg)](https://www.npmjs.com/package/react-aplayer) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/sabrinaluo/react-aplayer/blob/master/LICENSE)
4+
5+
🍭 Wow, A react wrapper of the beautiful HTML5 music [APlayer](https://github.com/MoePlayer/APlayer)
36

47
## Introduction
5-
[Demo](http://sabrinaluo.com/react-aplayer/)
8+
[Demo](http://sabrinaluo.github.io/react-aplayer/)
69

7-
Screen shot
8-
[![](https://camo.githubusercontent.com/a69d395460135e5542a3fd3f9a09d3817d17c228/68747470733a2f2f692e696d6775722e636f6d2f4a44724a5843722e706e67)]()
10+
### List with lyrics
11+
![image](https://user-images.githubusercontent.com/5300359/38107595-f7fd325a-33c4-11e8-9a9a-5d60613c9458.png)
12+
13+
### :star2: Fixed Mode
14+
![image](https://user-images.githubusercontent.com/5300359/38107623-11ad0874-33c5-11e8-8e0b-1e9625571e4b.png)
915

1016
## Usage
1117

@@ -15,92 +21,73 @@ npm install react-aplayer --save
1521
```
1622

1723
### Example
18-
```
24+
Check `src/app.js` to get more example;
25+
26+
```javascript
1927
import React from 'react';
2028
import ReactAplayer from 'react-aplayer';
2129

2230
export default class App extends React.Component {
23-
constructor(props) {
24-
super(props);
25-
this.state = {};
26-
}
27-
28-
playHandler() {
31+
// event binding example
32+
onPlay = () => {
2933
console.log('on play');
30-
}
34+
};
3135

32-
pauseHandler() {
36+
onPause = () => {
3337
console.log('on pause');
34-
}
38+
};
39+
40+
// example of access aplayer instance
41+
onInit = ap => {
42+
this.ap = ap;
43+
};
3544

3645
render() {
3746
const props = {
38-
"autoplay": true,
39-
"mutex": true,
40-
"preload": "metadata",
41-
"music": {
42-
"author": "Hans Zimmer/Richard Harvey",
43-
"url": "http://devtest.qiniudn.com/Preparation.mp3",
44-
"pic": "http://devtest.qiniudn.com/Preparation.jpg"
45-
}
47+
theme: '#F57F17',
48+
lrcType: 3,
49+
audio: [
50+
{
51+
name: '光るなら',
52+
artist: 'Goose house',
53+
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
54+
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
55+
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.lrc',
56+
theme: '#ebd0c2'
57+
}
58+
]
4659
};
4760

4861
return (
49-
<ReactAplayer {...props} onPlay={this.playHandler} onPause={this.pauseHandler}/>
62+
<div>
63+
<ReactAplayer
64+
{...props}
65+
onInit={this.onInit}
66+
onPlay={this.onPlay}
67+
onPause={this.onPause}
68+
/>
69+
{/* example of access aplayer instance API */}
70+
<button onClick={() => this.ap.toggle()}>toggle</button>
71+
<div>
5072
);
5173
}
5274
}
5375
```
5476

5577
### Props
56-
Props are almost the same with original APlayer, please check the [docs](https://aplayer.js.org/docs/#/) for more details.
57-
58-
| Name | Type | Required | Default | Description |
59-
|---|---|---|---|---|
60-
|autoplay| Boolean | N |`false` | |
61-
|listmaxheight| String | N | N/A |e.g. `'80px'` |
62-
|mode| String | |`'circulation'`|One of `'circulation'`, `'order'`, `'random'`, `'single'`|
63-
|mute| Boolean | |`false`| |
64-
|narrow| Boolean | |`false`| |
65-
|preload| String | |`'auto'`|One of `'auto'`, `'metadata'`, `'none'`|
66-
|showlrc| Number | |`0`| |
67-
|theme| String | |`'#b7daff'`| |
68-
|music| Array \| Object | Y | N/A | |
69-
|music.url| String | Y | | |
70-
|music.title| String | | N/A | |
71-
|music.author| String | | N/A | |
72-
|music.pic| String | | N/A | |
73-
|music.lrc| String | | N/A | |
78+
**`onInit`** as a callback function will be invoked when aplayer instance get initialized and with the instance as parameter, through which you can get the full control of aplayer API. *see `onInit` in above example*
7479

75-
### Event Handlers
76-
Event handlers are triggered when corresponding event happens, it takes a callback function as param.
80+
Other props are exactly the same with original APlayer, please check the [docs](https://aplayer.js.org/#/home) for more details.
7781

78-
|Name|Type | Description |
79-
|---|---|---|
80-
|onPlay| Func | |
81-
|onCanplay| Func | |
82-
|onPlay| Func | |
83-
|onPause| Func | |
84-
|onPlaying| Func | |
85-
|onEnded| Func | |
86-
|onError| Func | |
82+
### Event Handlers
83+
Event handlers are triggered when corresponding event happens, it takes a callback function as parameter.
8784

88-
### APlayer Instance & Bind Methods
89-
APlayer Instance can be accessed through `.state.control`.
85+
All the event handlers in `react-aplayer` are in a format of captalized event name prefixed with `on`, e.g. in aplayer, event `play` will be `onPlay` in react-aplayer,
9086

91-
```
92-
<ReactAplayer {...props} ref={(ap) => {
93-
const aplayer = ap.state.control;
94-
}/>
95-
```
87+
Please check the [docs](https://aplayer.js.org/#/home?id=event-binding) for more events.
9688

97-
To expose APlayer methods on React level, binding is needed.
98-
```
99-
<ReactAplayer {...props} ref={(ap) => {
100-
const player = ap.state.control;
101-
this.play = player.play.bind(player);
102-
}}/>
103-
```
89+
### APlayer Instance
90+
APlayer Instance can be accessed through `onInit`
10491

10592
## LICENSE
10693
[MIT License](https://github.com/sabrinaluo/react-aplayer/blob/master/LICENSE)

0 commit comments

Comments
 (0)