From 652a44026f12d47bc21e1a042a0a80e809c1a874 Mon Sep 17 00:00:00 2001 From: Brandon Bay Date: Wed, 13 May 2015 15:10:55 -0700 Subject: [PATCH] @bc-bbay fixed a bug where the player would try to autoplay when there was no source. closes #2127 --- CHANGELOG.md | 1 + src/js/media/html5.js | 2 +- test/unit/media.html5.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1455093805..d48a3bc318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) -------------------- 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;