Allen 4 years ago
parent
commit
94cdf5abe9
1 changed files with 38 additions and 26 deletions
  1. 38
    26
      src/components/AudioPlayer/index.js

+ 38
- 26
src/components/AudioPlayer/index.js View File

23
   componentDidMount() {
23
   componentDidMount() {
24
     if (this.player) {
24
     if (this.player) {
25
       const { src } = this.props;
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
         this.setState({ isPlaying: true, isLoading: false });
44
         this.setState({ isPlaying: true, isLoading: false });
45
+      };
40
       this.player.ontimeupdate = event =>
46
       this.player.ontimeupdate = event =>
41
         this.setState({ currentDuration: event.target.currentTime });
47
         this.setState({ currentDuration: event.target.currentTime });
42
       this.player.src = src;
48
       this.player.src = src;
45
 
51
 
46
   componentDidUpdate(prevProps) {
52
   componentDidUpdate(prevProps) {
47
     if (this.props.src !== prevProps.src) {
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
         this.setState({ isPlaying: true, isLoading: false });
72
         this.setState({ isPlaying: true, isLoading: false });
73
+      };
62
       this.player.ontimeupdate = event =>
74
       this.player.ontimeupdate = event =>
63
         this.setState({ currentDuration: event.target.currentTime });
75
         this.setState({ currentDuration: event.target.currentTime });
64
       this.player.src = this.props.src;
76
       this.player.src = this.props.src;