A plugin that displays user-friendly messages when Video.js encounters an error.
The plugin automatically registers itself when you include videojs.errors.js in your page:
You probably want to include the default stylesheet, too. It displays error messages as a semi-transparent overlay on top of the video element itself. It's designed to match up fairly well with the default Video.js styles:
If you're not a fan of the default styling, you can drop in your own stylesheet. The only new element to worry about is
vjs-errors-dialog which is the container for the error messages.
The plugin supports multiple languages when using Video.JS v4.7.3 or greater. In order to add additional language support, add the language file after your plugin as follows:
Note: A formatted example is available for Spanish under 'lang/es.js'.
Once you've initialized Video.js, you can activate the errors plugin. The plugin has a set of default error messages for the standard HTML5 video errors keyed off their runtime values:
Additionally, some custom errors have been added as reference for future extension.
PLAYER_ERRversus the standardized
MEDIA_ERRto avoid confusion.
If the video element emits any of those errors, the corresponding error message will be displayed. You can override and add custom error codes by supplying options to the plugin:
Or by calling
player.errors.extend after initializing the plugin:
If you define custom error messages, you'll need to let Video.js know when to emit them yourself:
If an error is emitted that doesn't have an associated key, a generic, catch-all message is displayed. You can override that text by supplying a message for the key
On iPhones, default errors are not dismissible. The video element intercepts all user interaction so error message dialogs miss the tap events. If your video is busted anyways, you may not be that upset about this.