From 8d9ac5134cac790cc65b2745c6155e8dcbadbe14 Mon Sep 17 00:00:00 2001 From: Kyle Lim Date: Thu, 1 Feb 2018 17:33:47 -0500 Subject: [PATCH] Fixed Autoplay Bug Finally fixed the bug that would autoplay the Youtube video when joining a dailymotion room late. Added a call to pause youtube whenever changing the player due to a sync. --- js/player.js | 5 ++++- js/yt.js | 3 +++ server.js | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/js/player.js b/js/player.js index ce815c7..b1f66aa 100644 --- a/js/player.js +++ b/js/player.js @@ -36,7 +36,10 @@ socket.on('createDaily', function(data) { var daily = document.getElementById('dailyArea'); daily.style.display='block'; currPlayer = 1 - console.log("hey i am number 1") + + // Special call to pause youtube player + // Only have to do on youtube player as it is the default player that autoplays + player.pauseVideo(); } }); diff --git a/js/yt.js b/js/yt.js index ec9f232..7509b11 100644 --- a/js/yt.js +++ b/js/yt.js @@ -10,6 +10,9 @@ var playerStatus = -1; function onYouTubeIframeAPIReady() { player = new YT.Player('player', { + playerVars: { + autoplay: 0 + }, events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange diff --git a/server.js b/server.js index 1e2aad2..824d057 100644 --- a/server.js +++ b/server.js @@ -94,6 +94,10 @@ io.sockets.on('connection', function(socket){ io.sockets.adapter.rooms['room-'+roomnum].currPlayer = playerId console.log(io.sockets.adapter.rooms['room-'+socket.roomnum].currPlayer) + // This syncs the host whenever the player changes + host = io.sockets.adapter.rooms['room-'+socket.roomnum].host + socket.broadcast.to(host).emit('getData'); + }); // Change video player @@ -181,7 +185,7 @@ io.sockets.on('connection', function(socket){ // Sets the default values when first initializing if (init){ io.sockets.adapter.rooms['room-'+socket.roomnum].currPlayer = 0 - io.sockets.adapter.rooms['room-'+socket.roomnum].currVideo = 'M7lc1UVf-VE' + io.sockets.adapter.rooms['room-'+socket.roomnum].currVideo = '' } // Gets current video from room variable