Skip to content

Commit

Permalink
Addressed comments in #1191
Browse files Browse the repository at this point in the history
Now clearing errors on loadstart events.
Added some default error messages.
  • Loading branch information
heff committed May 9, 2014
1 parent a742239 commit c7ad732
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 71 deletions.
1 change: 1 addition & 0 deletions build/source-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var sourceFiles = [
"src/js/button.js",
"src/js/slider.js",
"src/js/menu.js",
"src/js/media-error.js",
"src/js/player.js",
"src/js/control-bar/control-bar.js",
"src/js/control-bar/live-display.js",
Expand Down
1 change: 1 addition & 0 deletions src/css/video-js.less
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ easily in the skin designer. http://designer.videojs.com/
content: 'X';
font-family: Arial;
font-size: 4em;
color: #666666;
/* In order to center the play icon vertically we need to set the line height
to the same as the button height */
line-height: 1;
Expand Down
4 changes: 1 addition & 3 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ vjs.options = {
},

// Default message to show when a video cannot be played.
'notSupportedMessage': 'No compatible source ' +
'was found for this video. Learn more about' +
' <a href="http://www.videojs.com/html5-video-support/">supporting video</a>.'
'notSupportedMessage': 'No compatible source was found for this video.'
};

// Set CDN Version of swf
Expand Down
69 changes: 69 additions & 0 deletions src/js/media-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Custom MediaError to mimic the HTML5 MediaError
* @param {Number} code The media error code
*/
vjs.MediaError = function(code){
if (typeof code == 'number') {
this.code = code;
} else if (typeof code == 'string') {
// default code is zero, so this is a custom error
this.message = code;
} else if (typeof code == 'object') { // object
vjs.obj.merge(this, code);
}

if (!this.message) {
this.message = vjs.MediaError.defaultMessages[this.code] || '';
}
};

/**
* The error code that refers two one of the defined
* MediaError types
* @type {Number}
*/
vjs.MediaError.prototype.code = 0;

/**
* An optional message to be shown with the error.
* Message is not part of the HTML5 video spec
* but allows for more informative custom errors.
* @type {String}
*/
vjs.MediaError.prototype.message = '';

/**
* An optional status code that can be set by plugins
* to allow even more detail about the error.
* For example the HLS plugin might provide the specific
* HTTP status code that was returned when the error
* occurred, then allowing a custom error overlay
* to display more information.
* @type {[type]}
*/
vjs.MediaError.prototype.status = null;

vjs.MediaError.errorTypes = [
'MEDIA_ERR_CUSTOM', // = 0
'MEDIA_ERR_ABORTED', // = 1
'MEDIA_ERR_NETWORK', // = 2
'MEDIA_ERR_DECODE', // = 3
'MEDIA_ERR_SRC_NOT_SUPPORTED', // = 4
'MEDIA_ERR_ENCRYPTED' // = 5
];

vjs.MediaError.defaultMessages = {
1: 'You aborted the video playback',
2: 'A network error caused the video download to fail part-way.',
3: 'The video playback was aborted due to a corruption problem or because the video used features your browser did not support.',
4: 'The video could not be loaded, either because the server or network failed or because the format is not supported.',
5: 'The video is encrypted and we do not have the keys to decrypt it.'
};

// Add types as properties on MediaError
// e.g. MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
for (var errNum = 0; errNum < vjs.MediaError.errorTypes.length; errNum++) {
vjs.MediaError[vjs.MediaError.errorTypes[errNum]] = errNum;
// values should be accessible on both the class and instance
vjs.MediaError.prototype[vjs.MediaError.errorTypes[errNum]] = errNum;
}
76 changes: 9 additions & 67 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ vjs.Player.prototype.onLoadStart = function() {
this.off('play', initFirstPlay);
this.one('play', initFirstPlay);

if (this.error()) {
this.error(null);
}

vjs.removeClass(this.el_, 'vjs-has-started');
};

Expand Down Expand Up @@ -620,12 +624,11 @@ vjs.Player.prototype.techGet = function(method){
* @return {vjs.Player} self
*/
vjs.Player.prototype.play = function(){
if (this.error()) {
// In the case of an error, trying to play again wont fix the issue
// so we're blocking calling play in this case.
// We might log an error when this happpens, but this is probably too chatty.
// vjs.log.error('The error must be resolved before attempting to play the video');
} else {
// In the case of an error, trying to play again wont fix the issue
// so we're blocking calling play in this case.
// We might log an error when this happpens, but this is probably too chatty.
// vjs.log.error('The error must be resolved before attempting to play the video');
if (!this.error()) {
this.techCall('play');
}

Expand Down Expand Up @@ -1267,46 +1270,6 @@ vjs.Player.prototype.usingNativeControls = function(bool){
return this.usingNativeControls_;
};

/**
* Custom MediaError to mimic the HTML5 MediaError
* @param {Number} code The media error code
*/
vjs.MediaError = function(code){
if (typeof code == 'number') {
this.code = code;
} else if (typeof code == 'string') {
// default code is zero, so this is a custom error
this.message = code;
} else if (typeof code == 'object') { // object
vjs.obj.merge(this, code);
}
};

vjs.MediaError.prototype.code = 0;

// message is not part of the HTML5 video spec
// but allows for more informative custom errors
vjs.MediaError.prototype.message = '';

vjs.MediaError.prototype.status = null;

vjs.MediaError.errorTypes = [
'MEDIA_ERR_CUSTOM', // = 0
'MEDIA_ERR_ABORTED', // = 1
'MEDIA_ERR_NETWORK', // = 2
'MEDIA_ERR_DECODE', // = 3
'MEDIA_ERR_SRC_NOT_SUPPORTED', // = 4
'MEDIA_ERR_ENCRYPTED' // = 5
];

// Add types as properties on MediaError
// e.g. MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
for (var errNum = 0; errNum < vjs.MediaError.errorTypes.length; errNum++) {
vjs.MediaError[vjs.MediaError.errorTypes[errNum]] = errNum;
// values should be accessible on both the class and instance
vjs.MediaError.prototype[vjs.MediaError.errorTypes[errNum]] = errNum;
}

/**
* Store the current media error
* @type {Object}
Expand Down Expand Up @@ -1352,27 +1315,6 @@ vjs.Player.prototype.error = function(err){
return this;
};

// vjs.Player.prototype.waiting_ = false;

// vjs.Player.prototype.waiting = function(bool){
// if (bool === undefined) {
// return this.waiting_;
// }

// var wasWaiting = this.waiting_;
// this.waiting_ = bool;

// // trigger an event if it's newly waiting
// if (!wasWaiting && bool) {
// this.addClass('vjs-waiting');
// this.trigger('waiting');
// } else {
// this.removeClass('vjs-waiting');
// }

// return this;
// };

vjs.Player.prototype.ended = function(){ return this.techGet('ended'); };
vjs.Player.prototype.seeking = function(){ return this.techGet('seeking'); };

Expand Down
2 changes: 1 addition & 1 deletion test/unit/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('should get tag, source, and track settings', function(){
fixture.innerHTML += html;

var tag = document.getElementById('example_1');
var player = new vjs.Player(tag);
var player = PlayerTest.makePlayer({}, tag);

ok(player.options_['autoplay'] === true);
ok(player.options_['preload'] === 'none'); // No extern. Use string.
Expand Down

0 comments on commit c7ad732

Please sign in to comment.