|
@@ -23,20 +23,26 @@ class AudioPlayer extends React.Component {
|
23
|
23
|
componentDidMount() {
|
24
|
24
|
if (this.player) {
|
25
|
25
|
const { src } = this.props;
|
26
|
|
- this.player.oncanplay = event =>
|
27
|
|
- this.setState({
|
28
|
|
- duration: event.target.duration
|
29
|
|
- });
|
30
|
|
- this.player.onended = () =>
|
31
|
|
- this.setState({
|
32
|
|
- isPlaying: false,
|
33
|
|
- currentDuration: 0,
|
34
|
|
- isLoading: false
|
35
|
|
- });
|
36
|
|
- this.player.onpause = () =>
|
37
|
|
- this.setState({ isPlaying: false, isLoading: false });
|
38
|
|
- this.player.onplaying = () =>
|
|
26
|
+ this.player.oncanplay = event => {
|
|
27
|
+ console.log(event, 1111);
|
|
28
|
+ this.setState({ duration: event.target.duration });
|
|
29
|
+ };
|
|
30
|
+ this.player.onended = event => {
|
|
31
|
+ console.log(event, 2222);
|
|
32
|
+ this.setState({ isPlaying: false, currentDuration: 0 });
|
|
33
|
+ };
|
|
34
|
+ this.player.onpause = event => {
|
|
35
|
+ console.log(event, 333);
|
|
36
|
+ this.setState({ isPlaying: false });
|
|
37
|
+ };
|
|
38
|
+ this.player.onplay = () => {
|
|
39
|
+ console.log(event, 5555);
|
|
40
|
+ this.setState({ isPlaying: true, isLoading: false });
|
|
41
|
+ };
|
|
42
|
+ this.player.onplaying = event => {
|
|
43
|
+ console.log(event, 4444);
|
39
|
44
|
this.setState({ isPlaying: true, isLoading: false });
|
|
45
|
+ };
|
40
|
46
|
this.player.ontimeupdate = event =>
|
41
|
47
|
this.setState({ currentDuration: event.target.currentTime });
|
42
|
48
|
this.player.src = src;
|
|
@@ -45,20 +51,26 @@ class AudioPlayer extends React.Component {
|
45
|
51
|
|
46
|
52
|
componentDidUpdate(prevProps) {
|
47
|
53
|
if (this.props.src !== prevProps.src) {
|
48
|
|
- this.player.oncanplay = event =>
|
49
|
|
- this.setState({
|
50
|
|
- duration: event.target.duration
|
51
|
|
- });
|
52
|
|
- this.player.onended = () =>
|
53
|
|
- this.setState({
|
54
|
|
- isPlaying: false,
|
55
|
|
- currentDuration: 0,
|
56
|
|
- isLoading: false
|
57
|
|
- });
|
58
|
|
- this.player.onpause = () =>
|
59
|
|
- this.setState({ isPlaying: false, isLoading: false });
|
60
|
|
- this.player.onplaying = () =>
|
|
54
|
+ this.player.oncanplay = event => {
|
|
55
|
+ console.log(event, 1111);
|
|
56
|
+ this.setState({ duration: event.target.duration });
|
|
57
|
+ };
|
|
58
|
+ this.player.onended = event => {
|
|
59
|
+ console.log(event, 2222);
|
|
60
|
+ this.setState({ isPlaying: false, currentDuration: 0 });
|
|
61
|
+ };
|
|
62
|
+ this.player.onpause = event => {
|
|
63
|
+ console.log(event, 333);
|
|
64
|
+ this.setState({ isPlaying: false });
|
|
65
|
+ };
|
|
66
|
+ this.player.onplay = () => {
|
|
67
|
+ console.log(event, 5555);
|
|
68
|
+ this.setState({ isPlaying: true, isLoading: false });
|
|
69
|
+ };
|
|
70
|
+ this.player.onplaying = event => {
|
|
71
|
+ console.log(event, 4444);
|
61
|
72
|
this.setState({ isPlaying: true, isLoading: false });
|
|
73
|
+ };
|
62
|
74
|
this.player.ontimeupdate = event =>
|
63
|
75
|
this.setState({ currentDuration: event.target.currentTime });
|
64
|
76
|
this.player.src = this.props.src;
|