Skip to content

Commit

Permalink
@bc-bbay fixed a bug where the player would try to autoplay when ther…
Browse files Browse the repository at this point in the history
…e was no source. closes #2127
  • Loading branch information
bc-bbay authored and heff committed May 13, 2015
1 parent ec53eda commit 652a440
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CHANGELOG

## HEAD (Unreleased)
* @tjenkinson Added background-color to vjs-poster to remove transparent borders around scaled poster image ([view](https://github.com/videojs/video.js/pull/2138))
* @bc-bbay fixed a bug where the player would try to autoplay when there was no source ([view](https://github.com/videojs/video.js/pull/2127))

--------------------

Expand Down
2 changes: 1 addition & 1 deletion src/js/media/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ vjs.Html5 = vjs.MediaTechController.extend({
// In Chrome (15), if you have autoplay + a poster + no controls, the video gets hidden (but audio plays)
// This fixes both issues. Need to wait for API, so it updates displays correctly
player.ready(function(){
if (this.tag && this.options_['autoplay'] && this.paused()) {
if (this.src() && this.tag && this.options_['autoplay'] && this.paused()) {
delete this.tag['poster']; // Chrome Fix. Fixed in Chrome v16.
this.play();
}
Expand Down
33 changes: 33 additions & 0 deletions test/unit/media.html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,39 @@ test('should have the source handler interface', function() {
ok(vjs.Html5.registerSourceHandler, 'has the registerSourceHandler function');
});

test('should not autoplay if there is no source', function() {
var
plays = 0,
i = 0,
readyQueue = [];

player.play = function() {
plays ++;
};

player.ready = function(func) {
readyQueue.push(func);
};

player.src = function() { return ''; };

//re-initialized the tech to catch the callback in the readyQueue
tech = new vjs.Html5(player, {});

//set up other options to bypass the condition
player.options_['autoplay'] = true;
player.paused = function () {
return true;
};
player.tag = 'tag';

for (; i < readyQueue.length; i++) {
readyQueue[i].call(player);
}

equal(plays, 0, 'did not autoplay');
});

test('native source handler canHandleSource', function(){
var result;

Expand Down

0 comments on commit 652a440

Please sign in to comment.