diff --git a/src/js/media/html5.js b/src/js/media/html5.js index ee55d54e62..6c29f19e5e 100644 --- a/src/js/media/html5.js +++ b/src/js/media/html5.js @@ -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(); } diff --git a/test/unit/media.html5.js b/test/unit/media.html5.js index 606db155de..b4493a7e70 100644 --- a/test/unit/media.html5.js +++ b/test/unit/media.html5.js @@ -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;