Pārlūkot izejas kodu

fix: 修复 audio 初始状态

Allen 4 gadus atpakaļ
vecāks
revīzija
e836b9dc37
1 mainītis faili ar 6 papildinājumiem un 8 dzēšanām
  1. 6
    8
      src/components/AudioPlayer/index.js

+ 6
- 8
src/components/AudioPlayer/index.js Parādīt failu

@@ -25,9 +25,7 @@ class AudioPlayer extends React.Component {
25 25
       const { src } = this.props;
26 26
       this.player.oncanplay = event =>
27 27
         this.setState({
28
-          duration: event.target.duration,
29
-          isLoading: false,
30
-          isPlaying: true
28
+          duration: event.target.duration
31 29
         });
32 30
       this.player.onended = () =>
33 31
         this.setState({
@@ -37,7 +35,8 @@ class AudioPlayer extends React.Component {
37 35
         });
38 36
       this.player.onpause = () =>
39 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 40
       this.player.ontimeupdate = event =>
42 41
         this.setState({ currentDuration: event.target.currentTime });
43 42
       this.player.src = src;
@@ -48,9 +47,7 @@ class AudioPlayer extends React.Component {
48 47
     if (this.props.src !== prevProps.src) {
49 48
       this.player.oncanplay = event =>
50 49
         this.setState({
51
-          duration: event.target.duration,
52
-          isLoading: false,
53
-          isPlaying: true
50
+          duration: event.target.duration
54 51
         });
55 52
       this.player.onended = () =>
56 53
         this.setState({
@@ -60,7 +57,8 @@ class AudioPlayer extends React.Component {
60 57
         });
61 58
       this.player.onpause = () =>
62 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 62
       this.player.ontimeupdate = event =>
65 63
         this.setState({ currentDuration: event.target.currentTime });
66 64
       this.player.src = this.props.src;