diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 650299b9..234372d7 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -106,8 +106,8 @@ var YouTubePlayer = function (data) { //socket.emit("playerReady"); }, onStateChange: function(ev) { - if(PLAYER.paused && ev.data != YT.PlayerState.PAUSED - || !PLAYER.paused && ev.data == YT.PlayerState.PAUSED) { + if(PLAYER.paused && ev.data != YT.PlayerState.PAUSED || + !PLAYER.paused && ev.data == YT.PlayerState.PAUSED) { self.paused = (ev.data == YT.PlayerState.PAUSED); if(CLIENT.leader) sendVideoUpdate(); @@ -130,17 +130,17 @@ var YouTubePlayer = function (data) { self.player.setPlaybackQuality(VIDEOQUALITY); self.videoId = data.id; } - } + }; self.pause = function() { if(self.player.pauseVideo) self.player.pauseVideo(); - } + }; self.play = function() { if(self.player.playVideo) self.player.playVideo(); - } + }; self.isPaused = function(callback) { if(self.player.getPlayerState) { @@ -149,19 +149,19 @@ var YouTubePlayer = function (data) { } else { callback(false); } - } + }; self.getTime = function(callback) { if(self.player.getCurrentTime) callback(self.player.getCurrentTime()); - } + }; self.seek = function(time) { if(self.player.seekTo) self.player.seekTo(time, true); - } + }; }); -} +}; var VimeoPlayer = function (data) { var self = this; @@ -201,380 +201,277 @@ var VimeoPlayer = function (data) { sendVideoUpdate(); }); }.bind(self)); - } + }; self.init(); - self.load = function(data) { + self.load = function (data) { self.videoId = data.id; self.init(); - } + }; - self.pause = function() { + self.pause = function () { if(self.player && self.player.api) self.player.api("pause"); - } + }; - self.play = function() { + self.play = function () { if(self.player && self.player.api) self.player.api("play"); - } + }; - self.isPaused = function(callback) { + self.isPaused = function (callback) { callback(self.paused); - } + }; - self.getTime = function(callback) { + self.getTime = function (callback) { if(self.player && self.player.api) { // Vimeo api returns time as a string because fuck logic - self.player.api("getCurrentTime", function(time) { + self.player.api("getCurrentTime", function (time) { callback(parseFloat(time)); }); } - } + }; self.seek = function(time) { if(self.player && self.player.api) self.player.api("seekTo", time); - } + }; }); -} +}; -Player.prototype.nullPlayer = function() { - this.player = null; - this.load = function(data) { } - this.play = function() { } - this.pause = function() { } - this.getTime = function(callback) { } - this.seek = function(time) { } -} +var VimeoFlashPlayer = function (data) { + var self = this; + self.videoId = data.id; + self.init = function () { + removeOld(); + var url = "http://vimeo.com/moogaloop.swf?clip_id="+self.videoId; + url += "&" + [ + "server=vimeo.com", + "api=2", + "show_title=0", + "show_byline=0", + "show_portrait=0", + "fullscreen=1", + "loop=0" + ].join("&"); + var flashvars = { + api: 2, + player_id: "ytapiplayer" + }; + var params = { + allowfullscreen: true, + allowScriptAccess: "always" + }; + swfobject.embedSWF(url, + "ytapiplayer", + VWIDTH, + VHEIGHT, + "9.0.0", + "expressInstall.swf", + flashvars, + params); -Player.prototype.initYouTube = function() { - this.removeOld(); - this.player = new YT.Player("ytapiplayer", { - height: VHEIGHT, - width: VWIDTH, - videoId: this.id, - playerVars: { - autohide: 1, // Autohide controls - autoplay: 1, // Autoplay video - controls: 1, // Show controls - iv_load_policy: 3, // No annotations - modestbranding: 1, // No logo - rel: 0 // No related videos - }, - events: { - onReady: function() { - socket.emit("playerReady"); - }, - onStateChange: function(ev) { - if(PLAYER.paused && ev.data != YT.PlayerState.PAUSED - || !PLAYER.paused && ev.data == YT.PlayerState.PAUSED) { - PLAYER.paused = (ev.data == YT.PlayerState.PAUSED); - sendVideoUpdate(); - } - else { - PLAYER.paused = (ev.data == YT.PlayerState.PAUSED); - } - if(CLIENT.leader && ev.data == YT.PlayerState.ENDED) { + self.player = $("#ytapiplayer")[0]; + waitUntilDefined(self.player, "api_addEventListener", function () { + self.player.api_addEventListener("ready", function () { + //socket.emit("playerReady"); + self.player.api_play(); + + self.player.api_addEvent("finish", function () { + if(CLIENT.leader) + socket.emit("playNext"); + }); + + self.player.api_addEvent("pause", function () { + PLAYER.paused = true; + if(CLIENT.leader) + sendVideoUpdate(); + }); + + self.player.api_addEvent("play", function () { + PLAYER.paused = false; + if(CLIENT.leader) + sendVideoUpdate(); + }); + }); + }); + }; + + self.init(); + + self.load = function (data) { + self.videoId = data.id; + self.init(); + }; + + self.pause = function () { + if(self.player && self.player.api_pause) + self.player.api_pause(); + }; + + self.play = function () { + if(self.player && self.player.api_play) + self.player.api_play(); + }; + + self.isPaused = function (callback) { + callback(self.paused); + }; + + self.getTime = function (callback) { + if(self.player && self.player.api_getCurrentTime) { + var t = parseFloat(self.player.api_getCurrentTime()); + callback(t); + } + }; + + self.seek = function (time) { + if(self.player.api_seekTo); + self.player.api_seekTo(time); + }; +}; + +var DailymotionPlayer = function (data) { + var self = this; + waitUntilDefined(window, "DM", function () { + removeOld(); + self.videoId = data.id; + self.player = DM.player("ytapiplayer", { + video: data.id, + width: parseInt(VWIDTH), + height: parseInt(VHEIGHT), + params: { autoplay: 1 } + }); + + self.player.addEventListener("apiready", function (e) { + //socket.emit("playerReady"); + self.player.addEventListener("ended", function (e) { + if(CLIENT.leader) { socket.emit("playNext"); } - } - } - }); - $("#ytapiplayer").css("border", "none"); - - this.load = function(data) { - if(this.player.loadVideoById) { - this.player.loadVideoById(data.id, data.currentTime); - if(VIDEOQUALITY) - this.player.setPlaybackQuality(VIDEOQUALITY); - this.id = data.id; - } - } - - this.pause = function() { - if(this.player.pauseVideo) - this.player.pauseVideo(); - } - - this.play = function() { - if(this.player.playVideo) - this.player.playVideo(); - } - - this.isPaused = function(callback) { - callback(this.player.getPlayerState() != YT.PlayerState.PLAYING); - } - - this.getTime = function(callback) { - if(this.player.getCurrentTime) - callback(this.player.getCurrentTime()); - } - - this.seek = function(time) { - if(this.player.seekTo) - this.player.seekTo(time, true); - } -} - -Player.prototype.initVimeo = function() { - var iframe = $("