diff --git a/lib/channel/playlist.js b/lib/channel/playlist.js index e1bf11f9..efb3b38d 100644 --- a/lib/channel/playlist.js +++ b/lib/channel/playlist.js @@ -977,71 +977,72 @@ PlaylistModule.prototype.startPlayback = function (time) { var media = self.current.media; 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")) { self.channel.activeLock.lock(); vimeoWorkaround(media.id, function (direct) { self.channel.activeLock.release(); if (self.current && self.current.media === media) { self.current.media.meta.direct = direct; - self.startPlayback(time); + continuePlayback(); } }); return; - } - - if (media.type === "gd" && isExpired(media) && !media.meta.failed) { + } else if (media.type === "gd" && isExpired(media) && !media.meta.failed) { self.channel.activeLock.lock(); - this.refreshGoogleDocs(function () { + self.refreshGoogleDocs(function () { self.channel.activeLock.release(); if (self.current && self.current.media === media) { - self.startPlayback(time); + continuePlayback(); } }); return; - } - - 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()); - } + } else { + continuePlayback(); } }