瀏覽代碼

fix(Video.js): prevent DOMException: The play() request was interrupted by a new load request

j8
Paweł Domas 4 年之前
父節點
當前提交
a605403029
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. 12
    1
      react/features/base/media/components/web/Video.js

+ 12
- 1
react/features/base/media/components/web/Video.js 查看文件

144
  */
144
  */
145
 class Video extends Component<Props> {
145
 class Video extends Component<Props> {
146
     _videoElement: ?Object;
146
     _videoElement: ?Object;
147
+    _mounted: boolean;
147
 
148
 
148
     /**
149
     /**
149
      * Default values for {@code Video} component's properties.
150
      * Default values for {@code Video} component's properties.
189
      * @returns {void}
190
      * @returns {void}
190
      */
191
      */
191
     componentDidMount() {
192
     componentDidMount() {
193
+        this._mounted = true;
194
+
192
         if (this._videoElement) {
195
         if (this._videoElement) {
193
             this._videoElement.volume = 0;
196
             this._videoElement.volume = 0;
194
             this._videoElement.onplaying = this._onVideoPlaying;
197
             this._videoElement.onplaying = this._onVideoPlaying;
200
             // Ensure the video gets play() called on it. This may be necessary in the
203
             // Ensure the video gets play() called on it. This may be necessary in the
201
             // case where the local video container was moved and re-attached, in which
204
             // case where the local video container was moved and re-attached, in which
202
             // case video does not autoplay.
205
             // case video does not autoplay.
203
-            this._videoElement.play();
206
+            this._videoElement.play()
207
+                .catch(error => {
208
+                    // Prevent uncaught "DOMException: The play() request was interrupted by a new load request"
209
+                    // when video playback takes long to start and it starts after the component was unmounted.
210
+                    if (this._mounted) {
211
+                        throw error;
212
+                    }
213
+                });
204
         }
214
         }
205
     }
215
     }
206
 
216
 
212
      * @returns {void}
222
      * @returns {void}
213
      */
223
      */
214
     componentWillUnmount() {
224
     componentWillUnmount() {
225
+        this._mounted = false;
215
         this._detachTrack(this.props.videoTrack);
226
         this._detachTrack(this.props.videoTrack);
216
     }
227
     }
217
 
228
 

Loading…
取消
儲存