This commit is contained in:
Calvin Montgomery 2014-06-17 19:11:41 -07:00
parent 5b76d4fb8c
commit 523bdfe065

View file

@ -977,71 +977,72 @@ PlaylistModule.prototype.startPlayback = function (time) {
var media = self.current.media; var media = self.current.media;
media.reset(); media.reset();
var continuePlayback = function () {
if (self.leader != null) {
media.paused = false;
media.currentTime = time || 0;
self.sendChangeMedia(self.channel.users);
self.channel.notifyModules("onMediaChange", self.current.media);
return;
}
/* Lead-in time of 3 seconds to allow clients to buffer */
time = time || -3;
media.paused = time < 0;
media.currentTime = time;
/* Module was already leading, stop the previous timer */
if (self._leadInterval) {
clearInterval(self._leadInterval);
self._leadInterval = false;
}
self.sendChangeMedia(self.channel.users);
self.channel.notifyModules("onMediaChange", self.current.media);
/* Only start the timer if the media item is not live, i.e. has a duration */
if (media.seconds > 0) {
self._lastUpdate = Date.now();
self._leadInterval = setInterval(function() {
self._leadLoop();
}, 1000);
}
/* Google Docs autorefresh */
if (self._gdRefreshTimer) {
clearInterval(self._gdRefreshTimer);
self._gdRefreshTimer = false;
}
if (media.type === "gd") {
self._gdRefreshTimer = setInterval(self.refreshGoogleDocs.bind(self), 3600000);
if (media.meta.expiration && media.meta.expiration < Date.now() + 3600000) {
setTimeout(self.refreshGoogleDocs.bind(self), media.meta.expiration - Date.now());
}
}
};
if (media.type === "vi" && !media.meta.direct && Config.get("vimeo-workaround")) { if (media.type === "vi" && !media.meta.direct && Config.get("vimeo-workaround")) {
self.channel.activeLock.lock(); self.channel.activeLock.lock();
vimeoWorkaround(media.id, function (direct) { vimeoWorkaround(media.id, function (direct) {
self.channel.activeLock.release(); self.channel.activeLock.release();
if (self.current && self.current.media === media) { if (self.current && self.current.media === media) {
self.current.media.meta.direct = direct; self.current.media.meta.direct = direct;
self.startPlayback(time); continuePlayback();
} }
}); });
return; return;
} } else if (media.type === "gd" && isExpired(media) && !media.meta.failed) {
if (media.type === "gd" && isExpired(media) && !media.meta.failed) {
self.channel.activeLock.lock(); self.channel.activeLock.lock();
this.refreshGoogleDocs(function () { self.refreshGoogleDocs(function () {
self.channel.activeLock.release(); self.channel.activeLock.release();
if (self.current && self.current.media === media) { if (self.current && self.current.media === media) {
self.startPlayback(time); continuePlayback();
} }
}); });
return; return;
} } else {
continuePlayback();
if (self.leader != null) {
media.paused = false;
media.currentTime = time || 0;
self.sendChangeMedia(self.channel.users);
self.channel.notifyModules("onMediaChange", this.current.media);
return;
}
/* Lead-in time of 3 seconds to allow clients to buffer */
time = time || -3;
media.paused = time < 0;
media.currentTime = time;
/* Module was already leading, stop the previous timer */
if (self._leadInterval) {
clearInterval(self._leadInterval);
self._leadInterval = false;
}
self.sendChangeMedia(self.channel.users);
self.channel.notifyModules("onMediaChange", this.current.media);
/* Only start the timer if the media item is not live, i.e. has a duration */
if (media.seconds > 0) {
self._lastUpdate = Date.now();
self._leadInterval = setInterval(function() {
self._leadLoop();
}, 1000);
}
/* Google Docs autorefresh */
if (this._gdRefreshTimer) {
clearInterval(this._gdRefreshTimer);
this._gdRefreshTimer = false;
}
if (media.type === "gd") {
this._gdRefreshTimer = setInterval(this.refreshGoogleDocs.bind(this), 3600000);
if (media.meta.expiration && media.meta.expiration < Date.now() + 3600000) {
var self = this;
setTimeout(this.refreshGoogleDocs.bind(this), media.meta.expiration - Date.now());
}
} }
} }