From 35fb504847243ecdbba42afa07b237998cff8426 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Wed, 24 Apr 2013 06:33:53 +0400 Subject: [PATCH] Fix channel update function, start working on compensative synch --- channel.js | 14 ++++++++++---- www/assets/js/media.js | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/channel.js b/channel.js index be1f1d04..6e20936b 100644 --- a/channel.js +++ b/channel.js @@ -711,8 +711,9 @@ Channel.prototype.playNext = function() { } this.position++; + var oid = this.media ? this.media.id : ""; this.media = this.queue[this.position]; - this.media.currentTime = 0; + this.media.currentTime = -1; this.sendAll("mediaUpdate", this.media.packupdate()); this.sendAll("updatePlaylistIdx", { @@ -725,7 +726,9 @@ Channel.prototype.playNext = function() { && this.media.type != "li" && this.media.type != "rt") { this.time = new Date().getTime(); - mediaUpdate(this, this.media.id); + if(this.media.id != oid) { + mediaUpdate(this, this.media.id); + } } } @@ -753,8 +756,9 @@ Channel.prototype.jumpTo = function(pos) { var old = this.position; this.position = pos; + var oid = this.media ? this.media.id : ""; this.media = this.queue[this.position]; - this.media.currentTime = 0; + this.media.currentTime = -1; this.sendAll("mediaUpdate", this.media.packupdate()); this.sendAll("updatePlaylistIdx", { @@ -767,7 +771,9 @@ Channel.prototype.jumpTo = function(pos) { && this.media.type != "li" && this.media.type != "rt") { this.time = new Date().getTime(); - mediaUpdate(this, this.media.id); + if(this.media.id != oid) { + mediaUpdate(this, this.media.id); + } } } diff --git a/www/assets/js/media.js b/www/assets/js/media.js index e5c3bb0c..f7fed455 100644 --- a/www/assets/js/media.js +++ b/www/assets/js/media.js @@ -1,6 +1,7 @@ var Media = function(data) { this.id = data.id; this.type = data.type; + this.lastdiff = 0; switch(this.type) { case "yt": @@ -279,15 +280,28 @@ Media.prototype.initRTMP = function() { Media.prototype.update = function(data) { if(data.id != this.id) { + if(data.currentTime < 0) { + data.currentTime = 0; + } this.load(data); } if(data.paused) { this.pause(); } this.getTime(function(seconds) { + var time = data.currentTime; + if(readCookie("sync_compensate")) { + var diff = time - seconds; + if(diff > 0) { + diff = diff > 5 ? 5 : diff; + time += diff; + diff = (diff + this.lastdiff) / 2 || 0; + this.lastdiff = diff; + } + } if(Math.abs(data.currentTime - seconds) > SYNC_THRESHOLD) { if(!LEADER) { - this.seek(data.currentTime); + this.seek(time); } } }.bind(this));