-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvideojs.errors.js
57 lines (52 loc) · 1.84 KB
/
videojs.errors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(function(){
var defaults, extend;
defaults = {
messages: {
// MEDIA_ERR_ABORTED
1: "The video download was cancelled",
// MEDIA_ERR_NETWORK
2: "The video connection was lost, please confirm you're connected to the internet",
// MEDIA_ERR_DECODE
3: "The video is bad or in a format that can't be played on your browser",
// MEDIA_ERR_SRC_NOT_SUPPORTED
4: "This video is either unavailable or not supported in this browser",
// MEDIA_ERR_ENCRYPTED (Chrome)
5: "The video you're trying to watch is encrypted and we don't know how to decrypt it",
unknown: "An unanticipated problem was encountered, check back soon and try again"
}
};
extend = function(obj){
var arg, prop, source;
for (arg in arguments) {
source = arguments[arg];
for (prop in source) {
if (source[prop] && typeof source[prop] === 'object') {
obj[prop] = extend(obj[prop] || {}, source[prop]);
} else {
obj[prop] = source[prop];
}
}
};
return obj;
};
videojs.plugin('errors', function(options){
var addEventListener, messages, settings;
settings = extend(defaults, options);
messages = settings.messages;
addEventListener = this.el().addEventListener || this.el().attachEvent;
this.on('error', function(event){
var code, dialog, player;
player = this;
code = event.target.error ? event.target.error.code : event.code;
// create the dialog
dialog = document.createElement('div');
dialog.className = 'vjs-error-dialog';
dialog.textContent = messages[code] || messages['unknown'];
addEventListener.call(dialog, 'click', function(event){
player.el().removeChild(dialog);
}, false);
// add it to the DOM
player.el().appendChild(dialog);
});
});
})();