Преглед изворни кода

[RN] Add ability to loop sounds

master
Saúl Ibarra Corretgé пре 6 година
родитељ
комит
7b0a6a2ee5

+ 13
- 8
react/features/base/media/components/AbstractAudio.js Прегледај датотеку

10
     currentTime?: number,
10
     currentTime?: number,
11
     pause: () => void,
11
     pause: () => void,
12
     play: () => void,
12
     play: () => void,
13
-    setSinkId?: string => void
13
+    setSinkId?: string => void,
14
+    stop: () => void
14
 };
15
 };
15
 
16
 
16
 /**
17
 /**
61
         this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
62
         this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
62
     }
63
     }
63
 
64
 
64
-    pause: () => void;
65
-
66
     /**
65
     /**
67
      * Attempts to pause the playback of the media.
66
      * Attempts to pause the playback of the media.
68
      *
67
      *
73
         this._audioElementImpl && this._audioElementImpl.pause();
72
         this._audioElementImpl && this._audioElementImpl.pause();
74
     }
73
     }
75
 
74
 
76
-    play: () => void;
77
-
78
     /**
75
     /**
79
-     * Attempts to being the playback of the media.
76
+     * Attempts to begin the playback of the media.
80
      *
77
      *
81
      * @public
78
      * @public
82
      * @returns {void}
79
      * @returns {void}
106
         typeof setRef === 'function' && setRef(element ? this : null);
103
         typeof setRef === 'function' && setRef(element ? this : null);
107
     }
104
     }
108
 
105
 
109
-    setSinkId: string => void;
110
-
111
     /**
106
     /**
112
      * Sets the sink ID (output device ID) on the underlying audio element.
107
      * Sets the sink ID (output device ID) on the underlying audio element.
113
      * NOTE: Currently, implemented only on Web.
108
      * NOTE: Currently, implemented only on Web.
120
             && typeof this._audioElementImpl.setSinkId === 'function'
115
             && typeof this._audioElementImpl.setSinkId === 'function'
121
             && this._audioElementImpl.setSinkId(sinkId);
116
             && this._audioElementImpl.setSinkId(sinkId);
122
     }
117
     }
118
+
119
+    /**
120
+     * Attempts to stop the playback of the media.
121
+     *
122
+     * @public
123
+     * @returns {void}
124
+     */
125
+    stop(): void {
126
+        this._audioElementImpl && this._audioElementImpl.stop();
127
+    }
123
 }
128
 }

+ 18
- 8
react/features/base/media/components/native/Audio.js Прегледај датотеку

12
  * {@link RTCView}.
12
  * {@link RTCView}.
13
  */
13
  */
14
 export default class Audio extends AbstractAudio {
14
 export default class Audio extends AbstractAudio {
15
-
16
     /**
15
     /**
17
      * Reference to 'react-native-sound} {@link Sound} instance.
16
      * Reference to 'react-native-sound} {@link Sound} instance.
18
      */
17
      */
19
-    _sound: Sound
18
+    _sound: ?Sound;
20
 
19
 
21
     /**
20
     /**
22
      * A callback passed to the 'react-native-sound''s {@link Sound} instance,
21
      * A callback passed to the 'react-native-sound''s {@link Sound} instance,
56
      */
55
      */
57
     componentWillUnmount() {
56
     componentWillUnmount() {
58
         if (this._sound) {
57
         if (this._sound) {
59
-            this.setAudioElementImpl(null);
60
             this._sound.release();
58
             this._sound.release();
61
             this._sound = null;
59
             this._sound = null;
60
+            this.setAudioElementImpl(null);
61
+        }
62
+    }
63
+
64
+    /**
65
+     * Attempts to begin the playback of the media.
66
+     *
67
+     * @inheritdoc
68
+     * @override
69
+     */
70
+    play() {
71
+        if (this._sound) {
72
+            this._sound.setNumberOfLoops(this.props.loop ? -1 : 0);
73
+            super.play();
62
         }
74
         }
63
     }
75
     }
64
 
76
 
81
      * @returns {void}
93
      * @returns {void}
82
      */
94
      */
83
     stop() {
95
     stop() {
84
-        // Currently not implemented for mobile. If needed, a possible
85
-        // implementation is:
86
-        // if (this._sound) {
87
-        //     this._sound.stop();
88
-        // }
96
+        if (this._sound) {
97
+            this._sound.stop();
98
+        }
89
     }
99
     }
90
 }
100
 }

Loading…
Откажи
Сачувај