1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-25 02:42:10 +02:00

@dmlap @gkatsev improve Flash tech error property and add an error setter to the base tech. closes #2517

This commit is contained in:
Gary Katsevman 2015-08-31 14:21:53 -04:00 committed by David LaPalomento
parent 547e82d8e8
commit 98315b0e52
5 changed files with 50 additions and 8 deletions

View File

@ -110,6 +110,7 @@ CHANGELOG
* @heff fixed cross-platform track tests by switching to a fake tech ([view](https://github.com/videojs/video.js/pull/2496))
* @gkatsev improved tech controls listener handling. ([view](https://github.com/videojs/video.js/pull/2511))
* @dmlap move seek on replay into the flash tech ([view](https://github.com/videojs/video.js/pull/2527))
* @dmlap @gkatsev improve Flash tech error property and add an error setter to the base tech ([view](https://github.com/videojs/video.js/pull/2517))
--------------------

View File

@ -1001,7 +1001,8 @@ class Player extends Component {
* @event error
*/
handleTechError() {
this.error(this.tech.error().code);
let error = this.tech.error();
this.error(error && error.code);
}
/**

View File

@ -300,7 +300,7 @@ class Flash extends Tech {
// Create setters and getters for attributes
const _api = Flash.prototype;
const _readWrite = 'rtmpConnection,rtmpStream,preload,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(',');
const _readOnly = 'error,networkState,readyState,initialTime,duration,startOffsetTime,paused,ended,videoTracks,audioTracks,videoWidth,videoHeight'.split(',');
const _readOnly = 'networkState,readyState,initialTime,duration,startOffsetTime,paused,ended,videoTracks,audioTracks,videoWidth,videoHeight'.split(',');
function _createSetter(attr){
var attrUpper = attr.charAt(0).toUpperCase() + attr.slice(1);
@ -440,15 +440,14 @@ Flash.onEvent = function(swfID, eventName){
// Log errors from the swf
Flash.onError = function(swfID, err){
const tech = Dom.getEl(swfID).tech;
const msg = 'FLASH: '+err;
// trigger MEDIA_ERR_SRC_NOT_SUPPORTED
if (err === 'srcnotfound') {
tech.trigger('error', { code: 4, message: msg });
// errors we haven't categorized into the media errors
} else {
tech.trigger('error', msg);
return tech.error(4);
}
// trigger a custom error
tech.error('FLASH: ' + err);
};
// Flash Version Check

View File

@ -11,6 +11,7 @@ import * as Fn from '../utils/fn.js';
import log from '../utils/log.js';
import { createTimeRange } from '../utils/time-ranges.js';
import { bufferedPercent } from '../utils/buffer.js';
import MediaError from '../media-error.js';
import window from 'global/window';
import document from 'global/document';
@ -265,6 +266,27 @@ class Tech extends Component {
super.dispose();
}
/**
* When invoked without an argument, returns a MediaError object
* representing the current error state of the player or null if
* there is no error. When invoked with an argument, set the current
* error state of the player.
* @param {MediaError=} err Optional an error object
* @return {MediaError} the current error object or null
* @method error
*/
error(err) {
if (err !== undefined) {
if (err instanceof MediaError) {
this.error_ = err;
} else {
this.error_ = new MediaError(err);
}
this.trigger('error');
}
return this.error_;
}
/**
* Return the time ranges that have been played through for the
* current source. This implementation is incomplete. It does not

View File

@ -3,6 +3,7 @@ var noop = function() {}, clock, oldTextTracks;
import Tech from '../../../src/js/tech/tech.js';
import { createTimeRange } from '../../../src/js/utils/time-ranges.js';
import extendsFn from '../../../src/js/extends.js';
import MediaError from '../../../src/js/media-error.js';
q.module('Media Tech', {
'setup': function() {
@ -195,6 +196,24 @@ test('should handle unsupported sources with the source handler API', function()
ok(usedNative, 'native source handler was used when an unsupported source was set');
});
test('should allow custom error events to be set', function() {
let tech = new Tech();
let errors = [];
tech.on('error', function() {
errors.push(tech.error());
});
equal(tech.error(), null, 'error is null by default');
tech.error(new MediaError(1));
equal(errors.length, 1, 'triggered an error event');
equal(errors[0].code, 1, 'set the proper code');
tech.error(2);
equal(errors.length, 2, 'triggered an error event');
equal(errors[1].code, 2, 'wrapped the error code');
});
test('should track whether a video has played', function() {
let tech = new Tech();