Skip to content

Commit

Permalink
Fixed Autoplay Bug
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kyle8998 committed Feb 1, 2018
1 parent 4c703f1 commit 8d9ac51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down
3 changes: 3 additions & 0 deletions js/yt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ var playerStatus = -1;

function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
playerVars: {
autoplay: 0
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
Expand Down
6 changes: 5 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d9ac51

Please sign in to comment.