Skip to content

Commit

Permalink
fix(FEC-8510): listen to the html video element error event only once (
Browse files Browse the repository at this point in the history
…#73)

* stop listening to the video element errors

listening through the engine, and calling canRecover

* fixing flow + removing redundant function

* change to MediaError object instead event.
  • Loading branch information
odedhutzler authored Aug 29, 2018
1 parent d4896fd commit 1070245
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions src/hls-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._hls.on(Hlsjs.Events.LEVEL_SWITCHED, this._onLevelSwitched.bind(this));
this._hls.on(Hlsjs.Events.AUDIO_TRACK_SWITCHED, this._onAudioTrackSwitched.bind(this));
this._onRecoveredCallback = () => this._onRecovered();
this._onVideoErrorCallback = e => this._onVideoError(e);
this._videoElement.addEventListener(EventType.ERROR, this._onVideoErrorCallback);
this._onAddTrack = this._onAddTrack.bind(this);
this._videoElement.addEventListener('addtrack', this._onAddTrack);
this._videoElement.textTracks.onaddtrack = this._onAddTrack;
Expand All @@ -231,20 +229,19 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {

/**
* video error event handler.
* @param {Event} event - the media error event
* @private
* @returns {void}
*/
_onVideoError(event: Event): void {
if (event.currentTarget instanceof HTMLMediaElement && event.currentTarget.error instanceof MediaError) {
const mediaError = event.currentTarget.error;
if (mediaError.code === mediaError.MEDIA_ERR_DECODE) {
HlsAdapter._logger.debug(
'The video playback was aborted due to a corruption problem or because the video used features your browser did not support.',
mediaError.message
);
this._handleMediaError();
}
* @param {MediaError} error - the media error
* @public
* @returns {boolean} if hls-adapter will try to recover
*/
handleMediaError(error: MediaError): boolean {
if (error.code === error.MEDIA_ERR_DECODE) {
HlsAdapter._logger.debug(
'The video playback was aborted due to a corruption problem or because the video used features your browser did not support.',
error.message
);
return this._handleMediaError();
} else {
return false;
}
}

Expand Down Expand Up @@ -298,18 +295,6 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._loadInternal();
}

/**
* Remove the error listener
* @private
* @returns {void}
*/
_removeVideoErrorListener(): void {
if (this._onVideoErrorCallback) {
this._videoElement.removeEventListener(EventType.ERROR, this._onVideoErrorCallback);
this._onVideoErrorCallback = null;
}
}

/**
* Remove the loadedmetadata listener, when recovering from media error.
* @private
Expand Down Expand Up @@ -828,7 +813,6 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._videoElement.textTracks.onaddtrack = null;
this._videoElement.removeEventListener('addtrack', this._onAddTrack);
this._removeRecoveredCallbackListener();
this._removeVideoErrorListener();
}

/**
Expand Down

0 comments on commit 1070245

Please sign in to comment.