mirror of https://github.com/calzoneman/sync.git
Implement #123
This commit is contained in:
parent
59fa9aa029
commit
22b10e3ffa
|
@ -1011,6 +1011,7 @@ Channel.prototype.tryUpdate = function(user, data) {
|
|||
}
|
||||
|
||||
this.media.currentTime = data.currentTime;
|
||||
this.media.paused = data.paused;
|
||||
this.sendAll("mediaUpdate", this.media.timeupdate());
|
||||
}
|
||||
|
||||
|
|
|
@ -436,7 +436,7 @@ Callbacks = {
|
|||
socket.emit("mediaUpdate", {
|
||||
id: PLAYER.id,
|
||||
currentTime: seconds,
|
||||
paused: false,
|
||||
paused: PLAYER.paused,
|
||||
type: PLAYER.type
|
||||
});
|
||||
});
|
||||
|
|
|
@ -48,6 +48,9 @@ Media.prototype.initYouTube = function() {
|
|||
socket.emit("playerReady");
|
||||
},
|
||||
onStateChange: function(ev) {
|
||||
PLAYER.paused = (ev.data == YT.PlayerState.PAUSED);
|
||||
if(PLAYER.paused) {
|
||||
}
|
||||
if(LEADER && ev.data == YT.PlayerState.ENDED) {
|
||||
socket.emit("playNext");
|
||||
}
|
||||
|
@ -94,6 +97,7 @@ Media.prototype.initVimeo = function() {
|
|||
|
||||
this.player = $f(iframe[0]);
|
||||
$f(iframe[0]).addEvent("ready", function() {
|
||||
socket.emit("playerReady");
|
||||
this.player = $f(iframe[0]);
|
||||
this.player.api("play");
|
||||
|
||||
|
@ -102,6 +106,14 @@ Media.prototype.initVimeo = function() {
|
|||
socket.emit("playNext");
|
||||
}
|
||||
});
|
||||
|
||||
this.player.addEvent("pause", function() {
|
||||
PLAYER.paused = true;
|
||||
});
|
||||
|
||||
this.player.addEvent("play", function() {
|
||||
PLAYER.paused = false;
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
this.load = function(data) {
|
||||
|
@ -135,11 +147,23 @@ Media.prototype.initDailymotion = function() {
|
|||
params: {autoplay: 1}
|
||||
});
|
||||
|
||||
this.player.addEventListener("ended", function(e) {
|
||||
if(LEADER) {
|
||||
socket.emit("playNext");
|
||||
}
|
||||
});
|
||||
this.player.addEventListener("apiready", function(e) {
|
||||
socket.emit("playerReady");
|
||||
this.player.addEventListener("ended", function(e) {
|
||||
if(LEADER) {
|
||||
socket.emit("playNext");
|
||||
}
|
||||
});
|
||||
|
||||
this.player.addEventListener("pause", function(e) {
|
||||
PLAYER.paused = true;
|
||||
});
|
||||
|
||||
this.player.addEventListener("playing", function(e) {
|
||||
PLAYER.paused = false;
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
|
||||
this.load = function(data) {
|
||||
this.id = data.id;
|
||||
|
@ -174,13 +198,25 @@ Media.prototype.initSoundcloud = function() {
|
|||
iframe.css("border", "none");
|
||||
|
||||
this.player = SC.Widget("ytapiplayer");
|
||||
this.player.load(this.id, {auto_play: true});
|
||||
|
||||
this.player.bind(SC.Widget.Events.FINISH, function() {
|
||||
if(LEADER) {
|
||||
socket.emit("playNext");
|
||||
}
|
||||
});
|
||||
this.player.bind(SC.Widget.Events.READY, function() {
|
||||
socket.emit("playerReady");
|
||||
this.player.load(this.id, {auto_play: true});
|
||||
|
||||
this.player.bind(SC.Widget.Events.PAUSE, function() {
|
||||
PLAYER.paused = true;
|
||||
});
|
||||
|
||||
this.player.bind(SC.Widget.Events.PLAY, function() {
|
||||
PLAYER.paused = false;
|
||||
});
|
||||
|
||||
this.player.bind(SC.Widget.Events.FINISH, function() {
|
||||
if(LEADER) {
|
||||
socket.emit("playNext");
|
||||
}
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
this.load = function(data) {
|
||||
this.id = data.id;
|
||||
|
@ -319,6 +355,9 @@ Media.prototype.update = function(data) {
|
|||
if(data.paused) {
|
||||
this.pause();
|
||||
}
|
||||
else if(!this.paused) {
|
||||
this.play();
|
||||
}
|
||||
if(LEADER) {
|
||||
return;
|
||||
}
|
||||
|
@ -326,20 +365,12 @@ Media.prototype.update = function(data) {
|
|||
var time = data.currentTime;
|
||||
var diff = time - seconds || time;
|
||||
|
||||
var a = USEROPTS.sync_accuracy + 1;
|
||||
// If 2 updates in a row have lag, compensate for buffering
|
||||
if(diff >= a && diff <= a*3 && this.diff >= a && this.diff <= a*3) {
|
||||
this.seek(time + diff);
|
||||
if(diff > USEROPTS.sync_accuracy) {
|
||||
this.seek(time);
|
||||
}
|
||||
else if(diff < -USEROPTS.sync_accuracy || diff >= USEROPTS.sync_accuracy) {
|
||||
if(diff < 0) {
|
||||
this.seek(time + 0.5);
|
||||
}
|
||||
else {
|
||||
this.seek(time);
|
||||
}
|
||||
else if(diff < -USEROPTS.sync_accuracy) {
|
||||
this.seek(time + 1);
|
||||
}
|
||||
this.diff = diff;
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue