|
1 | | -import React from 'react'; |
| 1 | +import React, { PureComponent } from 'react'; |
2 | 2 | import ReactAplayer from './react-aplayer'; |
3 | | -import appData from './data.json'; |
| 3 | +import appData from './data'; |
4 | 4 | import './app.css'; |
5 | 5 |
|
6 | | -export default class App extends React.Component { |
7 | | - constructor(props) { |
8 | | - super(props); |
9 | | - this.state = {}; |
10 | | - } |
11 | | - |
12 | | - playHandler() { |
| 6 | +class App extends PureComponent { |
| 7 | + // event binding example |
| 8 | + onPlay = () => { |
13 | 9 | console.log('on play'); |
14 | | - } |
| 10 | + }; |
15 | 11 |
|
16 | | - pauseHandler() { |
| 12 | + onPause = () => { |
17 | 13 | console.log('on pause'); |
18 | | - } |
| 14 | + }; |
| 15 | + |
| 16 | + // example of access aplayer instance |
| 17 | + initAp1 = ap => { |
| 18 | + this.ap1 = ap; |
| 19 | + }; |
19 | 20 |
|
20 | 21 | render() { |
21 | 22 | return ( |
22 | | - <div className="container"> |
| 23 | + <div className="landing"> |
23 | 24 | <h1 className="main-title">React Aplayer</h1> |
24 | | - <h2>A react wrapper of Aplayer</h2> |
25 | | - |
26 | | - <h3>Normal</h3> |
27 | | - <ReactAplayer |
28 | | - {...appData.apNormal} |
29 | | - onPlay={this.playHandler} |
30 | | - onPause={this.pauseHandler} |
31 | | - ref={ap => { |
32 | | - const player = ap.state.control; |
| 25 | + <h3>🍭 Wow, A react wrapper of the beautiful HTML5 music Aplayer</h3> |
33 | 26 |
|
34 | | - const methods = [ |
35 | | - 'play', |
36 | | - 'pause', |
37 | | - 'toggle', |
38 | | - 'volume', |
39 | | - 'addMusic', |
40 | | - 'destroy', |
41 | | - ]; |
42 | | - methods.forEach(method => { |
43 | | - this[method] = player[method].bind(player); |
44 | | - }); |
45 | | - }} |
46 | | - /> |
47 | | - <button onClick={() => this.play()}>play</button> |
48 | | - <button onClick={() => this.play(100)}>play(100)</button> |
49 | | - <button onClick={() => this.pause()}>pause</button> |
50 | | - <button onClick={() => this.toggle()}>toggle()</button> |
51 | | - <button onClick={() => this.volume(0.1)}>volume(0.1)</button> |
52 | | - <button onClick={() => this.addMusic(appData.apList.music)}> |
53 | | - addMusic() |
54 | | - </button> |
55 | | - <button onClick={() => this.destroy()}>destroy()</button> |
| 27 | + <div className="aplayer-wrap"> |
| 28 | + {/* example with detailed props */} |
| 29 | + <ReactAplayer |
| 30 | + {...appData.apLrcList} |
| 31 | + onInit={this.initAp1} |
| 32 | + onPlay={this.onPlay} |
| 33 | + onPause={this.onPause} |
| 34 | + /> |
| 35 | + {/* example of access aplayer instance API */} |
| 36 | + <span className="footer"> |
| 37 | + {' '} |
| 38 | + click button to try player control ->{' '} |
| 39 | + </span> |
| 40 | + <button onClick={() => this.ap1.toggle()}>toggle()</button> |
| 41 | + </div> |
56 | 42 |
|
57 | | - <h3>With playlist</h3> |
58 | | - <ReactAplayer |
59 | | - {...appData.apList} |
60 | | - ref={ap => { |
61 | | - const player = ap.state.control; |
62 | | - this.setMusic = player.setMusic.bind(player); |
63 | | - }} |
64 | | - /> |
65 | | - <button onClick={() => this.setMusic(2)}>setMusic(2)</button> |
| 43 | + {/* example with deconstructing props */} |
| 44 | + <ReactAplayer {...appData.apFixedLrcList} /> |
66 | 45 |
|
67 | | - <h3>With lyrics</h3> |
68 | | - <ReactAplayer {...appData.apLrc} /> |
| 46 | + <div className="landing-buttons"> |
| 47 | + <a |
| 48 | + className="landing-button" |
| 49 | + target="_blank" |
| 50 | + href="https://github.com/MoePlayer/react-aplayer" |
| 51 | + > |
| 52 | + GitHub |
| 53 | + </a> |
69 | 54 |
|
70 | | - <h3>With playlist and lyrics</h3> |
71 | | - <ReactAplayer {...appData.apLrcList} /> |
| 55 | + <a |
| 56 | + className="landing-button" |
| 57 | + target="_blank" |
| 58 | + href="https://github.com/MoePlayer/react-aplayer#react-aplayer" |
| 59 | + > |
| 60 | + React-Aplayer Docs |
| 61 | + </a> |
72 | 62 |
|
73 | | - <h3>Narrow</h3> |
74 | | - <ReactAplayer music={appData.apNormal.music} narrow={true} /> |
| 63 | + <a |
| 64 | + className="landing-button" |
| 65 | + target="_blank" |
| 66 | + href="https://aplayer.js.org/#/home" |
| 67 | + > |
| 68 | + Aplayer Docs |
| 69 | + </a> |
| 70 | + </div> |
75 | 71 | </div> |
76 | 72 | ); |
77 | 73 | } |
78 | 74 | } |
| 75 | + |
| 76 | +export default App; |
0 commit comments