Modify lead function for lead-in
This commit is contained in:
parent
6a2e7bb9e2
commit
851491e4ac
|
|
@ -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
|
Sat Sep 21 02:21 2013 CDT
|
||||||
* www/assets/js/ui.js, www/assets/js/ui.js, www/assets/js/util.js,
|
* 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
|
www/channel.html, www/assets/css/ytsync.css: Add quick buttons for
|
||||||
|
|
|
||||||
|
|
@ -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)
|
if(!this.current || !this.current.media)
|
||||||
return false;
|
return false;
|
||||||
this.current.media.paused = false;
|
if (!this.leading) {
|
||||||
this.current.media.currentTime = time || -1;
|
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;
|
var pl = this;
|
||||||
if(this._leadInterval) {
|
if(this._leadInterval) {
|
||||||
clearInterval(this._leadInterval);
|
clearInterval(this._leadInterval);
|
||||||
this._leadInterval = false;
|
this._leadInterval = false;
|
||||||
}
|
}
|
||||||
this.on("changeMedia")(this.current.media);
|
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._lastUpdate = Date.now();
|
||||||
this._leadInterval = setInterval(function() {
|
this._leadInterval = setInterval(function() {
|
||||||
pl._leadLoop();
|
pl._leadLoop();
|
||||||
|
|
@ -551,7 +560,20 @@ Playlist.prototype._leadLoop = function() {
|
||||||
return;
|
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._lastUpdate = Date.now();
|
||||||
this._counter++;
|
this._counter++;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -761,6 +761,7 @@ var CustomPlayer = function (data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleMediaUpdate(data) {
|
function handleMediaUpdate(data) {
|
||||||
|
var wait = data.currentTime < 0;
|
||||||
// Media change
|
// Media change
|
||||||
if(data.id && data.id !== PLAYER.videoId) {
|
if(data.id && data.id !== PLAYER.videoId) {
|
||||||
if(data.currentTime < 0)
|
if(data.currentTime < 0)
|
||||||
|
|
@ -768,6 +769,12 @@ function handleMediaUpdate(data) {
|
||||||
PLAYER.load(data);
|
PLAYER.load(data);
|
||||||
PLAYER.play();
|
PLAYER.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wait) {
|
||||||
|
PLAYER.seek(0);
|
||||||
|
PLAYER.pause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't synch if leader or synch disabled
|
// Don't synch if leader or synch disabled
|
||||||
if(CLIENT.leader || !USEROPTS.synch)
|
if(CLIENT.leader || !USEROPTS.synch)
|
||||||
|
|
@ -775,8 +782,12 @@ function handleMediaUpdate(data) {
|
||||||
|
|
||||||
// Handle pause/unpause
|
// Handle pause/unpause
|
||||||
if(data.paused) {
|
if(data.paused) {
|
||||||
PLAYER.seek(data.currentTime);
|
PLAYER.isPaused(function (paused) {
|
||||||
PLAYER.pause();
|
if (!paused) {
|
||||||
|
PLAYER.seek(data.currentTime);
|
||||||
|
PLAYER.pause();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
PLAYER.isPaused(function (paused) {
|
PLAYER.isPaused(function (paused) {
|
||||||
if(paused)
|
if(paused)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue