Modify lead function for lead-in

This commit is contained in:
calzoneman 2013-09-21 23:54:29 -05:00
parent 6a2e7bb9e2
commit 851491e4ac
3 changed files with 46 additions and 7 deletions

View file

@ -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++;