diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 688cda76..803a4e07 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -853,30 +853,23 @@ Callbacks = { if(data.type != "sc" && PLAYER.type == "sc") // [](/goddamnitmango) fixSoundcloudShit(); + if(data.type != "jw" && PLAYER.type == "jw") { // Is it so hard to not mess up my DOM? $("
").attr("id", "ytapiplayer") .insertBefore($("#ytapiplayer_wrapper")); $("#ytapiplayer_wrapper").remove(); } + if(data.type != PLAYER.type) { - if(data.type === "vi" && typeof $f !== "function") { - setTimeout(function () { - Callbacks.changeMedia(data); - }, 100); - return; - } - PLAYER = new Player(data); - } - if(PLAYER.update) { - PLAYER.update(data); + loadMediaPlayer(data); } + + handleMediaUpdate(data); }, mediaUpdate: function(data) { - if(PLAYER.update) { - PLAYER.update(data); - } + handleMediaUpdate(data); }, setPlaylistLocked: function(data) { diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 234372d7..b0617a42 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -11,67 +11,24 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI var VIMEO_FLASH = false; -var Player = function(data) { - if(!data) { - data = { - id: "", - type: "null" - }; - } - this.id = data.id; - this.type = data.type; - this.length = data.length; - this.currentTime = data.currentTime || 0; - this.diff = 0; +var constructors = { + "yt": YouTubePlayer, + "vi": VIMEO_FLASH ? VimeoFlashPlayer : VimeoPlayer, + "dm": DailymotionPlayer, + "sc": SouncloudPlayer, + "li": LivestreamPlayer, + "tw": TwitchTVPlayer, + "jt": JustinTVPlayer, + "us": UstreamPlayer, + "rt": RTMPPlayer, + "im": ImgurPlayer, + "cu": CustomPlayer +}; - function postInit() { - this.load(data); - } - postInit.bind(this); - - switch(this.type) { - case "yt": - this.initYouTube(); - break; - case "vi": - if(VIMEO_FLASH) - this.initVimeoFlash(); - else - this.initVimeo(); - break; - case "dm": - this.initDailymotion(); - break; - case "sc": - this.initSoundcloud(); - break; - case "li": - this.initLivestream(); - break; - case "tw": - this.initTwitch(); - break; - case "jt": - this.initJustinTV(); - break; - case "rt": - this.initRTMP(); - break; - case "jw": - this.initJWPlayer(); - break; - case "us": - this.initUstream(); - break; - case "im": - this.initImgur(); - break; - case "cu": - this.initCustom(); - break; - default: - this.nullPlayer(); - break; +function loadMediaPlayer(data) { + if(data.type in constructors) { + PLAYER = new constructors[data.type](data); + PLAYER.type = data.type; } } @@ -473,302 +430,377 @@ var SoundcloudPlayer = function (data) { }; }; -Player.prototype.initLivestream = function() { - this.removeOld(); - var flashvars = {channel: this.id}; - var params = {AllowScriptAccess: "always"}; - swfobject.embedSWF("http://cdn.livestream.com/chromelessPlayer/v20/playerapi.swf", "ytapiplayer", VWIDTH, VHEIGHT, "9.0.0", "expressInstall.swf", flashvars, params); - - this.load = function(data) { - this.id = data.id; - this.initLivestream(); - } - - this.pause = function() { } - - this.play = function() { } - - this.isPaused = function() { } - - this.getTime = function() { } - - this.seek = function() { } -} - -Player.prototype.initTwitch = function() { - this.removeOld(); - var url = "http://www.twitch.tv/widgets/live_embed_player.swf?channel="+this.id; - var params = { - allowFullScreen:"true", - allowScriptAccess:"always", - allowNetworking:"all", - movie:"http://www.twitch.tv/widgets/live_embed_player.swf", - id: "live_embed_player_flash", - flashvars:"hostname=www.twitch.tv&channel="+this.id+"&auto_play=true&start_volume=100" +var LivestreamPlayer = function (data) { + removeOld(); + var self = this; + self.videoId = data.id; + self.init = function () { + var flashvars = { channel: self.videoId }; + var params = { AllowScriptAccess: "always" }; + swfobject.embedSWF( + "http://cdn.livestream.com/chromelessPlayer/v20/playerapi.swf", + "ytapiplayer", + VWIDTH, VHEIGHT, + "9.0.0", + "expressInstall.swf", + flashvars, + params + ); }; - swfobject.embedSWF( url, "ytapiplayer", VWIDTH, VHEIGHT, "8", null, null, params, {} ); - this.load = function(data) { - this.id = data.id; - this.initTwitch(); - } + self.init(); - this.pause = function() { } - - this.play = function() { } - - this.isPaused = function() { } - - this.getTime = function() { } - - this.seek = function() { } -} - -Player.prototype.initJustinTV = function() { - this.removeOld(); - var url = "http://www.justin.tv/widgets/live_embed_player.swf?channel="+this.id; - var params = { - allowFullScreen:"true", - allowScriptAccess:"always", - allowNetworking:"all", - movie:"http://www.justin.tv/widgets/live_embed_player.swf", - id: "live_embed_player_flash", - flashvars:"hostname=www.justin.tv&channel="+this.id+"&auto_play=true&start_volume=100" + self.load = function(data) { + self.videoId = data.id; + self.init(); }; - swfobject.embedSWF( url, "ytapiplayer", VWIDTH, VHEIGHT, "8", null, null, params, {} ); - this.load = function(data) { - this.id = data.id; - this.initJustinTV(); - } + self.pause = function () { }; - this.pause = function() { } + self.play = function () { }; - this.play = function() { } + self.isPaused = function () { }; - this.isPaused = function() { } + self.getTime = function () { }; - this.getTime = function() { } - - this.seek = function() { } + self.seek = function () { }; } -Player.prototype.initRTMP = function() { - this.removeOld(); - var url = "http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf"; - var src = encodeURIComponent(this.id); - var params = { - allowFullScreen:"true", - allowScriptAccess:"always", - allowNetworking:"all", - wMode:"direct", - movie:"http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf", - flashvars:"src="+src+"&streamType=live&autoPlay=true" +var TwitchTVPlayer = function (data) { + removeOld(); + var self = this; + self.videoId = data.id; + self.init = function () { + var url = "http://www.twitch.tv/widgets/live_embed_player.swf?channel="+self.videoId; + var params = { + allowFullScreen: "true", + allowScriptAccess: "always", + allowNetworking: "all", + movie: "http://www.twitch.tv/widgets/live_embed_player.swf", + id: "live_embed_player_flash", + flashvars: "hostname=www.twitch.tv&channel="+self.videoId+"&auto_play=true&start_volume=100" }; - swfobject.embedSWF(url, "ytapiplayer", VWIDTH, VHEIGHT, "8", null, null, params, {} ); + swfobject.embedSWF(url, + "ytapiplayer", + VWIDTH, VHEIGHT, + "8", + null, null, + params, + {} + ); + }; - this.load = function(data) { - this.id = data.id; - this.initRTMP(); - } + self.init(); - this.pause = function() { } + self.load = function (data) { + self.videoId = data.id; + self.init(); + }; - this.play = function() { } + self.pause = function () { }; - this.isPaused = function() { } + self.play = function () { }; - this.getTime = function() { } + self.isPaused = function () { }; - this.seek = function() { } + self.getTime = function () { }; + + self.seek = function () { }; } -Player.prototype.initJWPlayer = function() { - if(typeof jwplayer == "undefined") { - setTimeout(function() { - this.initJWPlayer(); - }.bind(this), 100); - return; - } - this.removeOld(); +var JustinTVPlayer = function (data) { + removeOld(); + var self = this; + self.videoId = data.id; + self.init = function () { + var url = "http://www.justin.tv/widgets/live_embed_player.swf?channel="+self.videoId; + var params = { + allowFullScreen: "true", + allowScriptAccess: "always", + allowNetworking: "all", + movie: "http://www.justin.tv/widgets/live_embed_player.swf", + id: "live_embed_player_flash", + flashvars: "hostname=www.justin.tv&channel="+self.videoId+"&auto_play=true&start_volume=100" + }; + swfobject.embedSWF(url, + "ytapiplayer", + VWIDTH, VHEIGHT, + "8", + null, null, + params, + {} + ); + }; - jwplayer("ytapiplayer").setup({ - file: this.id, - width: VWIDTH, - height: VHEIGHT, - autostart: true - }); + self.init(); - jwplayer().onPlay(function() { - this.paused = false; - }.bind(this)); - jwplayer().onPause(function() { - this.paused = true; - }.bind(this)); - jwplayer().onComplete(function() { - socket.emit("playNext"); - }); + self.load = function (data) { + self.videoId = data.id; + self.init(); + }; - this.load = function(data) { - this.id = data.id; - this.initJWPlayer(); + self.pause = function () { }; + + self.play = function () { }; + + self.isPaused = function () { }; + + self.getTime = function () { }; + + self.seek = function () { }; +} + +var RTMPPlayer = function (data) { + removeOld(); + var self = this; + self.videoId = data.id; + self.init = function () { + var url = "http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf"; + var src = encodeURIComponent(self.videoId); + var params = { + allowFullScreen: "true", + allowScriptAccess: "always", + allowNetworking: "all", + wMode: "direct", + movie: "http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf", + flashvars: "src="+src+"&streamType=live&autoPlay=true" + }; + swfobject.embedSWF(url, + "ytapiplayer", + VWIDTH, VHEIGHT, + "8", + null, null, + params, + {} + ); + }; + + self.init(); + + self.load = function (data) { + self.videoId = data.id; + self.init(); + }; + + self.pause = function () { }; + + self.play = function () { }; + + self.isPaused = function () { }; + + self.getTime = function () { }; + + self.seek = function () { }; +} + +var JWPlayer = function (data) { + var self = this; + self.videoId = data.id; + self.init = function () { + removeOld(); + + jwplayer("ytapiplayer").setup({ + file: self.videoId, + width: VWIDTH, + height: VHEIGHT, + autostart: true + }); + + jwplayer().onPlay(function() { + self.paused = false; + if(CLIENT.leader) + sendVideoUpdate(); + }); + jwplayer().onPause(function() { + self.paused = true; + if(CLIENT.leader) + sendVideoUpdate(); + }); + jwplayer().onComplete(function() { + socket.emit("playNext"); + }); } - this.pause = function() { - jwplayer().pause(true); - } + waitUntilDefined(window, "jwplayer", function () { self.init(); }); - this.play = function() { - jwplayer().play(true); - } + self.load = function (data) { + self.videoId = data.id; + self.init(); + }; - this.isPaused = function(callback) { - callback(jwplayer().getState() !== "PLAYING"); - } + self.pause = function () { + if(jwplayer) + jwplayer().pause(true); + }; - this.getTime = function(callback) { + self.play = function () { + if(jwplayer) + jwplayer().play(true); + }; + + self.isPaused = function (callback) { + if(jwplayer) + callback(jwplayer().getState() !== "PLAYING"); + }; + + self.getTime = function (callback) { // Only return time for non-live media - if(jwplayer().getDuration() != -1) { + if(jwplayer && jwplayer().getDuration() != -1) { callback(jwplayer().getPosition()); } - } + }; - this.seek = function(time) { - jwplayer().seek(time); - } + self.seek = function (time) { + if(jwplayer) + jwplayer().seek(time); + }; } -Player.prototype.initUstream = function() { - var iframe = $("