Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure it's safe to call bufferedPercent before the SWF loads #2289

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/js/media/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -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;

Expand Down
14 changes: 14 additions & 0 deletions test/unit/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});