var VIMEO_FLASH = false; function removeOld(replace) { $("#sc_volume").remove(); replace = replace || $("
").addClass("embed-responsive-item"); var old = $("#ytapiplayer"); replace.insertBefore(old); old.remove(); replace.attr("id", "ytapiplayer"); } var YouTubePlayer = function (data) { var self = this; waitUntilDefined(window, "YT", function () { waitUntilDefined(YT, "Player", function () { removeOld(); self.paused = false; self.videoId = data.id; self.videoLength = data.seconds; self.theYouTubeDevsNeedToFixThisShit = false; var wmode = USEROPTS.wmode_transparent ? "transparent" : "opaque"; self.player = new YT.Player("ytapiplayer", { videoId: data.id, playerVars: { autohide: 1, // Autohide controls autoplay: 1, // Autoplay video controls: 1, // Show controls iv_load_policy: 3, // No annotations rel: 0, // No related videos wmode: wmode }, events: { onReady: function () { PLAYER.setVolume(VOLUME); }, onStateChange: function (ev) { /** * Race conditions suck. * Race conditions in other peoples' code that you can't fix * but are forced to work around suck more. */ if (ev.data === YT.PlayerState.PLAYING && self.theYouTubeDevsNeedToFixThisShit) { PLAYER.seek(0.000001); PLAYER.pause(); self.theYouTubeDevsNeedToFixThisShit = false; } 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(); } else { self.paused = (ev.data == YT.PlayerState.PAUSED); } if(CLIENT.leader && ev.data == YT.PlayerState.ENDED) { socket.emit("playNext"); } } } }); $("#ytapiplayer").css("border", "none"); }); }); self.load = function (data) { if(self.player && self.player.loadVideoById) { self.player.loadVideoById(data.id, data.currentTime); if (USEROPTS.default_quality) { self.player.setPlaybackQuality(USEROPTS.default_quality); // What's that? Another stupid hack for the HTML5 player? self.player.setPlaybackQuality(USEROPTS.default_quality); } self.videoId = data.id; self.videoLength = data.seconds; } }; self.pause = function () { if(self.player && self.player.pauseVideo) self.player.pauseVideo(); }; self.play = function () { if(self.player && self.player.playVideo) self.player.playVideo(); }; self.getTime = function (callback) { if(self.player && self.player.getCurrentTime) callback(self.player.getCurrentTime()); }; self.seek = function (time) { if(self.player && self.player.seekTo) self.player.seekTo(time, true); }; self.getVolume = function (cb) { if (!self.player || !self.player.getVolume || !self.player.isMuted) { return; } // YouTube's API is strange in the sense that getVolume() returns // the regular (unmuted) volume even if it is muted... // YouTube's volume is 0..100, normalize it to 0..1 var vol = self.player.isMuted() ? 0 : (self.player.getVolume() / 100); cb(vol); }; self.setVolume = function (vol) { if (self.player && self.player.setVolume) { if (vol > 0) { self.player.unMute(); } self.player.setVolume(vol * 100); } }; }; var VimeoPlayer = function (data) { var self = this; waitUntilDefined(window, "$f", function () { self.videoId = data.id; self.videoLength = data.seconds; self.init = function () { var iframe = $("