diff --git a/src/js/big-play-button.js b/src/js/big-play-button.js index c4fa98ade..5e4b3cf48 100644 --- a/src/js/big-play-button.js +++ b/src/js/big-play-button.js @@ -11,6 +11,10 @@ vjs.BigPlayButton = vjs.Button.extend({ init: function(player, options){ vjs.Button.call(this, player, options); + if (!player.controls()) { + this.hide(); + } + player.on('play', vjs.bind(this, this.hide)); // player.on('ended', vjs.bind(this, this.show)); } @@ -31,4 +35,4 @@ vjs.BigPlayButton.prototype.onClick = function(){ //this.player_.currentTime(0); //} this.player_.play(); -}; \ No newline at end of file +}; diff --git a/src/js/component.js b/src/js/component.js index 9b5e7a0d0..7cd2ba437 100644 --- a/src/js/component.js +++ b/src/js/component.js @@ -575,6 +575,21 @@ vjs.Component.prototype.unlockShowing = function(){ return this; }; +/** + * Disable component by making it unshowable + */ +vjs.Component.prototype.disable = function(){ + this.hide(); + this.show = function(){}; + this.fadeIn = function(){}; +}; + +// TODO: Get enable working +// vjs.Component.prototype.enable = function(){ +// this.fadeIn = vjs.Component.prototype.fadeIn; +// this.show = vjs.Component.prototype.show; +// }; + /** * If a value is provided it will change the width of the player to that value * otherwise the width is returned diff --git a/src/js/controls.js b/src/js/controls.js index 7ae365fa4..3a3cbc88c 100644 --- a/src/js/controls.js +++ b/src/js/controls.js @@ -15,6 +15,10 @@ vjs.ControlBar = vjs.Component.extend({ init: function(player, options){ vjs.Component.call(this, player, options); + if (!player.controls()) { + this.disable(); + } + player.one('play', vjs.bind(this, function(){ var touchstart, fadeIn = vjs.bind(this, this.fadeIn), diff --git a/src/js/player.js b/src/js/player.js index 436cf47c1..332e29421 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -427,6 +427,7 @@ vjs.Player.prototype.techCall = function(method, arg){ this.tech[method](arg); } catch(e) { vjs.log(e); + throw e; } } }; @@ -447,22 +448,19 @@ vjs.Player.prototype.techGet = function(method){ try { return this.tech[method](); } catch(e) { - // When building additional tech libs, an expected method may not be defined yet if (this.tech[method] === undefined) { vjs.log('Video.js: ' + method + ' method not defined for '+this.techName+' playback technology.', e); - } else { - // When a method isn't available on the object it throws a TypeError if (e.name == 'TypeError') { vjs.log('Video.js: ' + method + ' unavailable on '+this.techName+' playback technology element.', e); this.tech.isReady_ = false; - throw e; } else { vjs.log(e); } } + throw e; } } @@ -877,7 +875,11 @@ vjs.Player.prototype.controls_; */ vjs.Player.prototype.controls = function(controls){ if (controls !== undefined) { - this.controls_ = controls; + // Don't trigger a change event unless it actually changed + if (this.controls_ !== controls) { + this.controls_ = !!controls; // force boolean + this.trigger('controlschange'); + } } return this.controls_; }; diff --git a/src/js/poster.js b/src/js/poster.js index 73156598c..761ddc0d4 100644 --- a/src/js/poster.js +++ b/src/js/poster.js @@ -11,7 +11,7 @@ vjs.PosterImage = vjs.Button.extend({ init: function(player, options){ vjs.Button.call(this, player, options); - if (!player.poster()) { + if (!player.poster() || !player.controls()) { this.hide(); } @@ -41,4 +41,4 @@ vjs.PosterImage.prototype.createEl = function(){ vjs.PosterImage.prototype.onClick = function(){ this.player_.play(); -}; \ No newline at end of file +}; diff --git a/test/unit/controls.js b/test/unit/controls.js index 5b58fa738..e34e81044 100644 --- a/test/unit/controls.js +++ b/test/unit/controls.js @@ -14,7 +14,8 @@ test('should hide volume control if it\'s not supported', function(){ volumeControl: false } }, - volume: function(){} + volume: function(){}, + muted: function(){} }; volumeControl = new vjs.VolumeControl(player); diff --git a/test/unit/mediafaker.js b/test/unit/mediafaker.js index 1630a420f..29c29c4c1 100644 --- a/test/unit/mediafaker.js +++ b/test/unit/mediafaker.js @@ -32,6 +32,7 @@ vjs.MediaFaker.prototype.createEl = function(){ vjs.MediaFaker.prototype.currentTime = function(){ return 0; }; vjs.MediaFaker.prototype.volume = function(){ return 0; }; +vjs.MediaFaker.prototype.muted = function(){ return false; }; // Export vars for Closure Compiler vjs['MediaFaker'] = vjs.MediaFaker; diff --git a/test/unit/player.js b/test/unit/player.js index 7d837ec51..0fec80022 100644 --- a/test/unit/player.js +++ b/test/unit/player.js @@ -231,3 +231,22 @@ test('should be able to initialize player twice on the same tag using string ref //here it triggers error, because player was destroyed already after first dispose player.dispose(); }); + +test('should set controls and trigger event', function() { + expect(3); + + var player = PlayerTest.makePlayer({ 'controls': false }); + ok(player.controls() === false, 'controls set through options'); + player.controls(true); + ok(player.controls() === true, 'controls updated'); + + player.on('controlschange', function(){ + ok(true, 'controlschange fired once'); + }); + player.controls(false); + // Check for unnecessary controlschange events + player.controls(false); + + player.dispose(); +}); +