Sfoglia il codice sorgente

[RN] Add ability to loop sounds

master
Saúl Ibarra Corretgé 6 anni fa
parent
commit
7b0a6a2ee5

+ 13
- 8
react/features/base/media/components/AbstractAudio.js Vedi File

@@ -10,7 +10,8 @@ export type AudioElement = {
10 10
     currentTime?: number,
11 11
     pause: () => void,
12 12
     play: () => void,
13
-    setSinkId?: string => void
13
+    setSinkId?: string => void,
14
+    stop: () => void
14 15
 };
15 16
 
16 17
 /**
@@ -61,8 +62,6 @@ export default class AbstractAudio extends Component<Props> {
61 62
         this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
62 63
     }
63 64
 
64
-    pause: () => void;
65
-
66 65
     /**
67 66
      * Attempts to pause the playback of the media.
68 67
      *
@@ -73,10 +72,8 @@ export default class AbstractAudio extends Component<Props> {
73 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 78
      * @public
82 79
      * @returns {void}
@@ -106,8 +103,6 @@ export default class AbstractAudio extends Component<Props> {
106 103
         typeof setRef === 'function' && setRef(element ? this : null);
107 104
     }
108 105
 
109
-    setSinkId: string => void;
110
-
111 106
     /**
112 107
      * Sets the sink ID (output device ID) on the underlying audio element.
113 108
      * NOTE: Currently, implemented only on Web.
@@ -120,4 +115,14 @@ export default class AbstractAudio extends Component<Props> {
120 115
             && typeof this._audioElementImpl.setSinkId === 'function'
121 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 Vedi File

@@ -12,11 +12,10 @@ const logger = require('jitsi-meet-logger').getLogger(__filename);
12 12
  * {@link RTCView}.
13 13
  */
14 14
 export default class Audio extends AbstractAudio {
15
-
16 15
     /**
17 16
      * Reference to 'react-native-sound} {@link Sound} instance.
18 17
      */
19
-    _sound: Sound
18
+    _sound: ?Sound;
20 19
 
21 20
     /**
22 21
      * A callback passed to the 'react-native-sound''s {@link Sound} instance,
@@ -56,9 +55,22 @@ export default class Audio extends AbstractAudio {
56 55
      */
57 56
     componentWillUnmount() {
58 57
         if (this._sound) {
59
-            this.setAudioElementImpl(null);
60 58
             this._sound.release();
61 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,10 +93,8 @@ export default class Audio extends AbstractAudio {
81 93
      * @returns {void}
82 94
      */
83 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…
Annulla
Salva