From 851491e4ac94a3115d46236273fb7606faaa2e9e Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 21 Sep 2013 23:54:29 -0500 Subject: [PATCH] Modify lead function for lead-in --- changelog | 6 ++++++ lib/playlist.js | 32 +++++++++++++++++++++++++++----- www/assets/js/player.js | 15 +++++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/changelog b/changelog index 27a6e6ab..66d2143d 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,9 @@ +Sat Sep 21 23:53 2013 CDT + * lib/playlist.js, www/assets/js/player.js: Modify the server lead + function to have a 3 second lead-in period (to allow buffering). + Videos start at -3 seconds; the client is paused until the time + reaches 0 seconds. + Sat Sep 21 02:21 2013 CDT * www/assets/js/ui.js, www/assets/js/ui.js, www/assets/js/util.js, www/channel.html, www/assets/css/ytsync.css: Add quick buttons for diff --git a/lib/playlist.js b/lib/playlist.js index 624a6bdf..1e59657b 100644 --- a/lib/playlist.js +++ b/lib/playlist.js @@ -510,18 +510,27 @@ Playlist.prototype.lead = function(lead) { } } -Playlist.prototype.startPlayback = function(time) { +Playlist.prototype.startPlayback = function (time) { if(!this.current || !this.current.media) return false; - this.current.media.paused = false; - this.current.media.currentTime = time || -1; + if (!this.leading) { + this.current.media.paused = false; + this.current.media.currentTime = time || 0; + this.on("changeMedia")(this.current.media); + return; + } + + time = time || -3; + this.current.media.paused = time < 0; + this.current.media.currentTime = time; + var pl = this; if(this._leadInterval) { clearInterval(this._leadInterval); this._leadInterval = false; } this.on("changeMedia")(this.current.media); - if(this.leading && !isLive(this.current.media.type)) { + if(!isLive(this.current.media.type)) { this._lastUpdate = Date.now(); this._leadInterval = setInterval(function() { pl._leadLoop(); @@ -551,7 +560,20 @@ Playlist.prototype._leadLoop = function() { return; } - this.current.media.currentTime += (Date.now() - this._lastUpdate) / 1000.0; + var dt = (Date.now() - this._lastUpdate) / 1000.0; + var t = this.current.media.currentTime; + + // Transition from lead-in + if (t < 0 && (t + dt) >= 0) { + this.current.media.currentTime = 0; + this.current.media.paused = false; + this._counter = 0; + this._lastUpdate = Date.now(); + this.on("mediaUpdate")(this.current.media); + return; + } + + this.current.media.currentTime += dt; this._lastUpdate = Date.now(); this._counter++; diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 68d704c3..a944dfad 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -761,6 +761,7 @@ var CustomPlayer = function (data) { }; function handleMediaUpdate(data) { + var wait = data.currentTime < 0; // Media change if(data.id && data.id !== PLAYER.videoId) { if(data.currentTime < 0) @@ -768,6 +769,12 @@ function handleMediaUpdate(data) { PLAYER.load(data); PLAYER.play(); } + + if (wait) { + PLAYER.seek(0); + PLAYER.pause(); + return; + } // Don't synch if leader or synch disabled if(CLIENT.leader || !USEROPTS.synch) @@ -775,8 +782,12 @@ function handleMediaUpdate(data) { // Handle pause/unpause if(data.paused) { - PLAYER.seek(data.currentTime); - PLAYER.pause(); + PLAYER.isPaused(function (paused) { + if (!paused) { + PLAYER.seek(data.currentTime); + PLAYER.pause(); + } + }); } else { PLAYER.isPaused(function (paused) { if(paused)