Created
September 28, 2016 06:52
-
-
Save shokimble/044f784686af9d0df01187975248ef81 to your computer and use it in GitHub Desktop.
Brightcove customise error messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Custom errors | |
//Documented here http://docs.brightcove.com/en/perform/brightcove-player/guides/errors-plugin.html | |
(function(videojs) { | |
var defaults = { | |
errors: { | |
1: { | |
type: "MEDIA_ERR_ABORTED", | |
headline: "The video connection was lost", | |
message: "Please check your internet connection and try again", | |
}, | |
2: { | |
type: "MEDIA_ERR_NETWORK", | |
headline: "The video connection was lost", | |
message: "Please check your internet connection and try again", | |
}, | |
3: { | |
type: "MEDIA_ERR_DECODE", | |
headline: "Unable to playback video", | |
message: "The video you're trying to watch is not supported by this device or browser", | |
}, | |
4: { | |
type: "MEDIA_ERR_SRC_NOT_SUPPORTED", | |
headline: "Unable to playback video", | |
message: "The video you're trying to watch is not supported by this device or browser", | |
}, | |
5: { | |
type: "MEDIA_ERR_ENCRYPTED", | |
headline: "Unable to playback video", | |
message: "The video you're trying to watch is not supported by this device or browser", | |
}, | |
unknown: { | |
type: "MEDIA_ERR_UNKNOWN", | |
headline: "Unable to playback video", | |
message: "An unknown error has occurred. Please reload the page and try again", | |
}, | |
"-1": { | |
type: "PLAYER_ERR_NO_SRC", | |
headline: "Unable to playback video", | |
message: "Unfortunately we were not able to play the video you requested", | |
}, | |
"-2": { | |
type: "PLAYER_ERR_TIMEOUT", | |
headline: "The video connection was lost", | |
message: "Please check your internet connection and try again", | |
}, | |
"-3": { | |
type: "TZ_INCORRECT" | |
headline: "Wrong timezone", | |
message: 'Timezone incorrect<br><span><a href="/content/tvnz/ondemand/help/faqs.html" target="_blank">Help</a>' | |
} | |
} | |
}, | |
friendlyErrors = function(options) { | |
var player = this, | |
settings = videojs.mergeOptions(defaults, options); | |
player.on("error", function() { | |
var error, display, details = ""; | |
error = videojs.mergeOptions(this.error(), settings.errors[this.error().code || 0]); | |
if (error.message) { | |
details = '<div class="vjs-errors-details">' + '<div class="vjs-errors-message">' + this.localize(error.message) + "</div>" + "</div>" | |
} | |
if (!error.headline) { | |
error.headline = "Sorry!" | |
} | |
display = this.errorDisplay; | |
display.el().innerHTML = '<div class="vjs-errors-dialog">' + '<div class="vjs-errors-content-container">' + '<h2 class="vjs-errors-headline">' + this.localize(error.headline) + "</h2>" + this.localize(details) + "</div>" + "</div>"; | |
}) | |
}; | |
videojs.plugin("friendlyErrors", friendlyErrors); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment