From aee076dc3b14950dc0d1c8e11d2e0a95a01f837f Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 3 Oct 2015 08:49:07 +1000 Subject: [PATCH] Added autoplay option --- src/js/plyr.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/js/plyr.js b/src/js/plyr.js index 3ddb85b1..ed328202 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -18,6 +18,7 @@ var defaults = { enabled: true, debug: false, + autoplay: false, seekTime: 10, volume: 5, click: true, @@ -847,7 +848,7 @@ _toggleClass(player.container, config.classes.type.replace('{0}', player.type), true); // If there's no autoplay attribute, assume the video is stopped and add state class - _toggleClass(player.container, config.classes.stopped, (player.media.getAttribute('autoplay') === null)); + _toggleClass(player.container, config.classes.stopped, ((player.media.getAttribute('autoplay') === null) && !config.autoplay)); // Add iOS class if (player.browser.ios) { @@ -874,7 +875,7 @@ } // Autoplay - if (player.media.getAttribute('autoplay') !== null) { + if (player.media.getAttribute('autoplay') !== null || config.autoplay) { _play(); } } @@ -934,7 +935,7 @@ player.embed = new YT.Player(container.id, { videoId: id, playerVars: { - autoplay: 0, + autoplay: (config.autoplay ? 1 : 0), controls: (player.supported.full ? 0 : 1), rel: 0, showinfo: 0, @@ -1701,7 +1702,7 @@ player.media.load(); // Play if autoplay attribute is present - if (player.media.getAttribute('autoplay') !== null) { + if (player.media.getAttribute('autoplay') !== null || config.autoplay) { _play(); } } @@ -1724,7 +1725,7 @@ if (!focused || focused == document.body) { focused = null; } - else if (document.querySelector) { + else { focused = document.querySelector(':focus'); } for (var button in player.buttons) {