forked from videojs/video.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error handling. closes videojs#1197
Squashed commit of the following: commit 81d7859 Author: Steve Heffernan <steve@zencoder.com> Date: Mon May 12 12:53:59 2014 -0700 Removed unneeded comments commit c7ad732 Author: Steve Heffernan <steve@zencoder.com> Date: Fri May 9 14:29:31 2014 -0700 Addressed comments in videojs#1191 Now clearing errors on loadstart events. Added some default error messages. commit a742239 Author: Steve Heffernan <steve@zencoder.com> Date: Wed May 7 15:38:31 2014 -0700 Fixed the error display to hide by default commit 561c3f8 Author: Steve Heffernan <steve@zencoder.com> Date: Mon May 5 10:44:47 2014 -0700 Added support for displaying a message for the error. commit 2214207 Author: Steve Heffernan <steve@zencoder.com> Date: Fri May 2 17:18:22 2014 -0700 Updated spinner to hide on all errors commit 95d7e70 Author: Steve Heffernan <steve@zencoder.com> Date: Fri May 2 15:37:44 2014 -0700 Exported ErrorDisplay commit 11ca9cd Author: Steve Heffernan <steve@zencoder.com> Date: Fri May 2 15:35:46 2014 -0700 Updated flash tech to support new errors commit 56cbe66 Author: Steve Heffernan <steve@zencoder.com> Date: Fri May 2 13:06:49 2014 -0700 Started on better error handling and displaying in the UI when an error has occurred. commit 740014c Author: Steve Heffernan <steve@zencoder.com> Date: Wed Apr 30 16:11:33 2014 -0700 Added better global log/error/warn functions. Added sinon.js for stubs in tests. Updated grunt version to satisfy peer dependency warning.
- Loading branch information
Showing
22 changed files
with
569 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
"start", | ||
"stop", | ||
"strictEqual", | ||
"test" | ||
"test", | ||
"sinon" | ||
] | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Display that an error has occurred making the video unplayable | ||
* @param {vjs.Player|Object} player | ||
* @param {Object=} options | ||
* @constructor | ||
*/ | ||
vjs.ErrorDisplay = vjs.Component.extend({ | ||
init: function(player, options){ | ||
vjs.Component.call(this, player, options); | ||
|
||
this.update(); | ||
player.on('error', vjs.bind(this, this.update)); | ||
} | ||
}); | ||
|
||
vjs.ErrorDisplay.prototype.createEl = function(){ | ||
var el = vjs.Component.prototype.createEl.call(this, 'div', { | ||
className: 'vjs-error-display' | ||
}); | ||
|
||
this.contentEl_ = vjs.createEl('div'); | ||
el.appendChild(this.contentEl_); | ||
|
||
return el; | ||
}; | ||
|
||
vjs.ErrorDisplay.prototype.update = function(){ | ||
if (this.player().error()) { | ||
this.contentEl_.innerHTML = this.player().error().message; | ||
} | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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; | ||
} |
This file contains 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
Oops, something went wrong.