Added autoplay option

This commit is contained in:
Sam Potts 2015-10-03 08:49:07 +10:00
parent 66969f1a65
commit aee076dc3b

View File

@ -18,6 +18,7 @@
var defaults = { var defaults = {
enabled: true, enabled: true,
debug: false, debug: false,
autoplay: false,
seekTime: 10, seekTime: 10,
volume: 5, volume: 5,
click: true, click: true,
@ -847,7 +848,7 @@
_toggleClass(player.container, config.classes.type.replace('{0}', player.type), true); _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 // 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 // Add iOS class
if (player.browser.ios) { if (player.browser.ios) {
@ -874,7 +875,7 @@
} }
// Autoplay // Autoplay
if (player.media.getAttribute('autoplay') !== null) { if (player.media.getAttribute('autoplay') !== null || config.autoplay) {
_play(); _play();
} }
} }
@ -934,7 +935,7 @@
player.embed = new YT.Player(container.id, { player.embed = new YT.Player(container.id, {
videoId: id, videoId: id,
playerVars: { playerVars: {
autoplay: 0, autoplay: (config.autoplay ? 1 : 0),
controls: (player.supported.full ? 0 : 1), controls: (player.supported.full ? 0 : 1),
rel: 0, rel: 0,
showinfo: 0, showinfo: 0,
@ -1701,7 +1702,7 @@
player.media.load(); player.media.load();
// Play if autoplay attribute is present // Play if autoplay attribute is present
if (player.media.getAttribute('autoplay') !== null) { if (player.media.getAttribute('autoplay') !== null || config.autoplay) {
_play(); _play();
} }
} }
@ -1724,7 +1725,7 @@
if (!focused || focused == document.body) { if (!focused || focused == document.body) {
focused = null; focused = null;
} }
else if (document.querySelector) { else {
focused = document.querySelector(':focus'); focused = document.querySelector(':focus');
} }
for (var button in player.buttons) { for (var button in player.buttons) {