diff --git a/src/js/media/flash.js b/src/js/media/flash.js index 6bf426887d..3a44f0cc21 100644 --- a/src/js/media/flash.js +++ b/src/js/media/flash.js @@ -174,9 +174,19 @@ vjs.Flash.prototype.seekable = function() { }; vjs.Flash.prototype.buffered = function(){ + if (!this.el_.vjs_getProperty) { + return vjs.createTimeRange(); + } return vjs.createTimeRange(0, this.el_.vjs_getProperty('buffered')); }; +vjs.Flash.prototype.duration = function(){ + if (!this.el_.vjs_getProperty) { + return 0; + } + return this.el_.vjs_getProperty('duration'); +}; + vjs.Flash.prototype.supportsFullScreen = function(){ return false; // Flash does not allow fullscreen through javascript }; @@ -189,7 +199,7 @@ vjs.Flash.prototype.enterFullScreen = function(){ // Create setters and getters for attributes var api = vjs.Flash.prototype, readWrite = 'rtmpConnection,rtmpStream,preload,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(','), - readOnly = 'error,networkState,readyState,seeking,initialTime,duration,startOffsetTime,paused,played,ended,videoTracks,audioTracks,videoWidth,videoHeight'.split(','), + readOnly = 'error,networkState,readyState,seeking,initialTime,startOffsetTime,paused,played,ended,videoTracks,audioTracks,videoWidth,videoHeight'.split(','), // Overridden: buffered, currentTime, currentSrc i; diff --git a/test/unit/flash.js b/test/unit/flash.js index 38051039f8..e8dce04827 100644 --- a/test/unit/flash.js +++ b/test/unit/flash.js @@ -186,3 +186,17 @@ test('seekable should be empty if no video is loaded', function() { equal(tech.seekable().length, 0, 'seekable is empty'); }); + +test('calling methods before the SWF loads is safe', function() { + var player = PlayerTest.makePlayer(), + tech = new vjs.Flash(player, { + 'parentEl': player.el() + }); + + // force Flash callbacks to be undefined as they would be before the + // SWF is ready + tech.el().vjs_getProperty = undefined; + + equal(tech.buffered().length, 0, 'buffered percent is 0'); + equal(tech.duration(), 0, 'duration is 0'); +});