Browse Source

fix: 修复 audio 初始状态

Allen 4 years ago
parent
commit
e836b9dc37
1 changed files with 6 additions and 8 deletions
  1. 6
    8
      src/components/AudioPlayer/index.js

+ 6
- 8
src/components/AudioPlayer/index.js View File

25
       const { src } = this.props;
25
       const { src } = this.props;
26
       this.player.oncanplay = event =>
26
       this.player.oncanplay = event =>
27
         this.setState({
27
         this.setState({
28
-          duration: event.target.duration,
29
-          isLoading: false,
30
-          isPlaying: true
28
+          duration: event.target.duration
31
         });
29
         });
32
       this.player.onended = () =>
30
       this.player.onended = () =>
33
         this.setState({
31
         this.setState({
37
         });
35
         });
38
       this.player.onpause = () =>
36
       this.player.onpause = () =>
39
         this.setState({ isPlaying: false, isLoading: false });
37
         this.setState({ isPlaying: false, isLoading: false });
40
-      // this.player.onplay = () => this.setState({ isLoading: true });
38
+      this.player.onplaying = () =>
39
+        this.setState({ isPlaying: true, isLoading: false });
41
       this.player.ontimeupdate = event =>
40
       this.player.ontimeupdate = event =>
42
         this.setState({ currentDuration: event.target.currentTime });
41
         this.setState({ currentDuration: event.target.currentTime });
43
       this.player.src = src;
42
       this.player.src = src;
48
     if (this.props.src !== prevProps.src) {
47
     if (this.props.src !== prevProps.src) {
49
       this.player.oncanplay = event =>
48
       this.player.oncanplay = event =>
50
         this.setState({
49
         this.setState({
51
-          duration: event.target.duration,
52
-          isLoading: false,
53
-          isPlaying: true
50
+          duration: event.target.duration
54
         });
51
         });
55
       this.player.onended = () =>
52
       this.player.onended = () =>
56
         this.setState({
53
         this.setState({
60
         });
57
         });
61
       this.player.onpause = () =>
58
       this.player.onpause = () =>
62
         this.setState({ isPlaying: false, isLoading: false });
59
         this.setState({ isPlaying: false, isLoading: false });
63
-      // this.player.onplay = () => this.setState({ isPlaying: false });
60
+      this.player.onplaying = () =>
61
+        this.setState({ isPlaying: true, isLoading: false });
64
       this.player.ontimeupdate = event =>
62
       this.player.ontimeupdate = event =>
65
         this.setState({ currentDuration: event.target.currentTime });
63
         this.setState({ currentDuration: event.target.currentTime });
66
       this.player.src = this.props.src;
64
       this.player.src = this.props.src;