Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Video.js errors instead letting the player crash #612

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/MediaPlayer/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ const MediaPlayer = ({
...hlsOptions,
nativeTextTracks: IS_MOBILE && !IS_ANDROID
},
// Make error display modal dismissable
errorDisplay: {
uncloseable: false,
},
/*
Setting this option helps to override VideoJS's default 'keydown' event handler, whenever
the focus is on a native VideoJS control icon (e.g. play toggle).
Expand Down
15 changes: 14 additions & 1 deletion src/components/MediaPlayer/VideoJS/VideoJSPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,28 +622,41 @@ function VideoJSPlayer({
// Use error event listener for inaccessible item display
player.on('error', (e) => {
const error = player.error();
let errorMessage = 'Something went wrong. Please try again later or contact support for help.';
// Handle different error codes
// TODO::In the future, this can be further improved to give proper feedback to the user when playback is not working
switch (error.code) {
case 1:
console.error('MEDIA_ERR_ABORTED: The fetching process for the media resource was aborted by the user agent\
at the user’s request.');
break;
case 2:
errorMessage = 'The media could not be loaded due to a network error. Please try again later.';
console.error('MEDIA_ERR_NETWORK: A network error caused the user agent to stop fetching the media resource,\
after the resource was established to be usable.');
break;
case 3:
errorMessage = 'Sorry, media appear to be corrupted or has features not supported by the browser. \
Please try a different media or contact support for help.';
Dananji marked this conversation as resolved.
Show resolved Hide resolved
console.error('MEDIA_ERR_DECODE: An error occurred while decoding the media resource, after\
the resource was established to be usable.');
break;
case 4:
errorMessage = 'Sorry, media could not be loaded, either the media format is not supported or due to a \
network error.';
Dananji marked this conversation as resolved.
Show resolved Hide resolved
console.error('MEDIA_ERR_SRC_NOT_SUPPORTED: The media resource indicated by the src attribute was not suitable.');
break;
default:
console.error('An unknown error occurred.');
break;
}
// Show dismissable error display modal from Video.js
var errorDisplay = player.getChild('ErrorDisplay');
if (errorDisplay) {
errorDisplay.contentEl().innerText = errorMessage;
errorDisplay.removeClass('vjs-hidden');
player.removeClass('vjs-error');
player.removeClass('vjs-disabled');
}
e.stopPropagation();
});
/*
Expand Down
12 changes: 6 additions & 6 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
width: 4em !important;
}

.vjs-error-display.vjs-modal-dialog .vjs-modal-dialog-content {
font-size: 1.5em;
padding: .5em;
text-align: center;
}

/* Prevent horizontal volume panel from attempting to close for audio */
.video-js .vjs-volume-panel.vjs-volume-panel-horizontal {
transition: none !important;
Expand All @@ -91,12 +97,6 @@
margin-top: 0.15em;
}

/* Make player height minimum to the controls height so when we hide
video/poster area the controls are displayed correctly. */
.video-js.vjs-audio {
min-height: 3.7em;
}

.video-js .vjs-progress-control:hover .vjs-play-progress:after {
display: none;
}
Expand Down