Skip to content
New issue

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

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

Already on GitHub? # to your account

Do not autoplay if no source defined #2127

Closed
wants to merge 3 commits 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
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