2013-07-28 14:49:12 +00:00
|
|
|
var VIMEO_FLASH = false;
|
|
|
|
|
2013-08-04 16:16:19 +00:00
|
|
|
function removeOld(replace) {
|
2013-08-07 18:25:08 +00:00
|
|
|
$("#sc_volume").remove();
|
2014-11-11 04:43:49 +00:00
|
|
|
replace = replace || $("<div/>").addClass("embed-responsive-item");
|
2013-08-04 16:16:19 +00:00
|
|
|
var old = $("#ytapiplayer");
|
|
|
|
replace.insertBefore(old);
|
|
|
|
old.remove();
|
|
|
|
replace.attr("id", "ytapiplayer");
|
|
|
|
}
|
|
|
|
|
|
|
|
var YouTubePlayer = function (data) {
|
|
|
|
var self = this;
|
|
|
|
waitUntilDefined(window, "YT", function () {
|
2013-08-06 15:42:20 +00:00
|
|
|
waitUntilDefined(YT, "Player", function () {
|
|
|
|
removeOld();
|
|
|
|
self.paused = false;
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2014-05-10 01:09:17 +00:00
|
|
|
self.theYouTubeDevsNeedToFixThisShit = false;
|
2015-01-04 21:46:40 +00:00
|
|
|
self.whyDoesSetPlaybackQualityHaveARaceCondition = true;
|
2013-08-06 15:42:20 +00:00
|
|
|
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
|
2013-08-04 16:16:19 +00:00
|
|
|
},
|
2013-08-06 15:42:20 +00:00
|
|
|
events: {
|
|
|
|
onReady: function () {
|
2014-02-03 02:04:50 +00:00
|
|
|
PLAYER.setVolume(VOLUME);
|
2013-08-06 15:42:20 +00:00
|
|
|
},
|
|
|
|
onStateChange: function (ev) {
|
2015-01-04 21:46:40 +00:00
|
|
|
if (self.whyDoesSetPlaybackQualityHaveARaceCondition) {
|
|
|
|
self.whyDoesSetPlaybackQualityHaveARaceCondition = false;
|
|
|
|
|
|
|
|
if (USEROPTS.default_quality) {
|
|
|
|
self.player.setPlaybackQuality(USEROPTS.default_quality);
|
|
|
|
}
|
|
|
|
}
|
2014-05-10 01:09:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2015-01-04 02:36:58 +00:00
|
|
|
|
|
|
|
if (USEROPTS.default_quality) {
|
|
|
|
self.player.setPlaybackQuality(USEROPTS.default_quality);
|
|
|
|
}
|
2014-05-10 01:09:17 +00:00
|
|
|
PLAYER.pause();
|
|
|
|
self.theYouTubeDevsNeedToFixThisShit = false;
|
|
|
|
}
|
|
|
|
|
2013-08-06 15:42:20 +00:00
|
|
|
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");
|
|
|
|
}
|
2013-08-04 16:16:19 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-06 15:42:20 +00:00
|
|
|
});
|
|
|
|
$("#ytapiplayer").css("border", "none");
|
2013-08-04 16:16:19 +00:00
|
|
|
});
|
|
|
|
});
|
2013-08-06 15:42:20 +00:00
|
|
|
|
|
|
|
self.load = function (data) {
|
|
|
|
if(self.player && self.player.loadVideoById) {
|
|
|
|
self.player.loadVideoById(data.id, data.currentTime);
|
2015-01-04 21:46:40 +00:00
|
|
|
self.whyDoesSetPlaybackQualityHaveARaceCondition = true;
|
|
|
|
if (USEROPTS.default_quality) {
|
|
|
|
// Try to set it ahead of time, if that works
|
|
|
|
// If not, the onStateChange callback will try again anyways
|
|
|
|
self.player.setPlaybackQuality(USEROPTS.default_quality);
|
|
|
|
}
|
2013-08-06 15:42:20 +00:00
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 15:42:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-08-04 16:16:19 +00:00
|
|
|
|
|
|
|
var VimeoPlayer = function (data) {
|
|
|
|
var self = this;
|
|
|
|
waitUntilDefined(window, "$f", function () {
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-04 16:16:19 +00:00
|
|
|
self.init = function () {
|
|
|
|
var iframe = $("<iframe/>");
|
|
|
|
removeOld(iframe);
|
2013-09-10 22:18:02 +00:00
|
|
|
var prto = location.protocol;
|
|
|
|
iframe.attr("src", prto+"//player.vimeo.com/video/"+self.videoId+"?api=1&player_id=ytapiplayer");
|
2013-08-04 16:16:19 +00:00
|
|
|
iframe.attr("webkitAllowFullScreen", "");
|
|
|
|
iframe.attr("mozallowfullscreen", "");
|
|
|
|
iframe.attr("allowFullScreen", "");
|
2013-08-06 15:42:20 +00:00
|
|
|
if(USEROPTS.wmode_transparent)
|
|
|
|
iframe.attr("wmode", "transparent");
|
2013-08-04 16:16:19 +00:00
|
|
|
iframe.css("border", "none");
|
|
|
|
|
|
|
|
$f(iframe[0]).addEvent("ready", function () {
|
|
|
|
self.player = $f(iframe[0]);
|
|
|
|
self.player.api("play");
|
|
|
|
|
|
|
|
self.player.addEvent("finish", function () {
|
|
|
|
if(CLIENT.leader) {
|
|
|
|
socket.emit("playNext");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
self.player.addEvent("pause", function () {
|
|
|
|
self.paused = true;
|
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
|
|
|
});
|
|
|
|
|
|
|
|
self.player.addEvent("play", function () {
|
|
|
|
self.paused = false;
|
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
|
|
|
});
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.setVolume(VOLUME);
|
2013-08-04 16:16:19 +00:00
|
|
|
}.bind(self));
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-08-04 16:16:19 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.load = function (data) {
|
2013-08-04 16:16:19 +00:00
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-04 16:16:19 +00:00
|
|
|
self.init();
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-08-04 16:16:19 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.pause = function () {
|
2013-08-04 16:16:19 +00:00
|
|
|
if(self.player && self.player.api)
|
|
|
|
self.player.api("pause");
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-08-04 16:16:19 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.play = function () {
|
2013-08-04 16:16:19 +00:00
|
|
|
if(self.player && self.player.api)
|
|
|
|
self.player.api("play");
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-08-04 16:16:19 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.getTime = function (callback) {
|
2013-08-04 16:16:19 +00:00
|
|
|
if(self.player && self.player.api) {
|
|
|
|
// Vimeo api returns time as a string because fuck logic
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.api("getCurrentTime", function (time) {
|
2013-08-04 16:16:19 +00:00
|
|
|
callback(parseFloat(time));
|
|
|
|
});
|
|
|
|
}
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-08-04 16:16:19 +00:00
|
|
|
|
|
|
|
self.seek = function(time) {
|
|
|
|
if(self.player && self.player.api)
|
|
|
|
self.player.api("seekTo", time);
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function (cb) {
|
|
|
|
if (self.player && self.player.api) {
|
|
|
|
self.player.api("getVolume", cb);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.setVolume = function (vol) {
|
|
|
|
self.player.api("setVolume", vol);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.init();
|
2013-06-11 15:29:21 +00:00
|
|
|
});
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
var VimeoFlashPlayer = function (data) {
|
|
|
|
var self = this;
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-05 04:19:10 +00:00
|
|
|
self.init = function () {
|
|
|
|
removeOld();
|
2013-09-10 22:18:02 +00:00
|
|
|
var prto = location.protocol;
|
|
|
|
var url = prto+"//vimeo.com/moogaloop.swf?clip_id="+self.videoId;
|
2013-08-05 04:19:10 +00:00
|
|
|
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,
|
2013-08-06 15:42:20 +00:00
|
|
|
allowScriptAccess: "always",
|
|
|
|
wmode: USEROPTS.wmode_transparent ? "transparent" : undefined
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
|
|
|
swfobject.embedSWF(url,
|
|
|
|
"ytapiplayer",
|
|
|
|
VWIDTH,
|
|
|
|
VHEIGHT,
|
|
|
|
"9.0.0",
|
|
|
|
"expressInstall.swf",
|
|
|
|
flashvars,
|
|
|
|
params);
|
|
|
|
|
|
|
|
self.player = $("#ytapiplayer")[0];
|
|
|
|
waitUntilDefined(self.player, "api_addEventListener", function () {
|
|
|
|
self.player.api_addEventListener("ready", function () {
|
|
|
|
self.player.api_play();
|
2013-07-12 20:34:55 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.api_addEvent("finish", function () {
|
|
|
|
if(CLIENT.leader)
|
|
|
|
socket.emit("playNext");
|
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.api_addEvent("pause", function () {
|
|
|
|
PLAYER.paused = true;
|
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.api_addEvent("play", function () {
|
|
|
|
PLAYER.paused = false;
|
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
|
|
|
});
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.setVolume(VOLUME);
|
2013-08-05 04:19:10 +00:00
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
});
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.load = function (data) {
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-05 04:19:10 +00:00
|
|
|
self.init();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.pause = function () {
|
|
|
|
if(self.player && self.player.api_pause)
|
|
|
|
self.player.api_pause();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.play = function () {
|
|
|
|
if(self.player && self.player.api_play)
|
|
|
|
self.player.api_play();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.getTime = function (callback) {
|
|
|
|
if(self.player && self.player.api_getCurrentTime) {
|
|
|
|
var t = parseFloat(self.player.api_getCurrentTime());
|
|
|
|
callback(t);
|
|
|
|
}
|
|
|
|
};
|
2013-07-12 20:34:55 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.seek = function (time) {
|
|
|
|
if(self.player.api_seekTo);
|
|
|
|
self.player.api_seekTo(time);
|
|
|
|
};
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function (cb) {
|
|
|
|
if (self.player && self.player.api_getVolume) {
|
|
|
|
cb(self.player.api_getVolume());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.setVolume = function (vol) {
|
|
|
|
self.player.api_setVolume(vol);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.init();
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
var DailymotionPlayer = function (data) {
|
|
|
|
var self = this;
|
|
|
|
waitUntilDefined(window, "DM", function () {
|
|
|
|
removeOld();
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2014-05-16 05:36:33 +00:00
|
|
|
|
|
|
|
var q = undefined;
|
|
|
|
if (USEROPTS.default_quality) {
|
|
|
|
/* Map youtube-style quality names to dailymotion values */
|
|
|
|
q = {
|
|
|
|
small: 240,
|
|
|
|
medium: 380,
|
|
|
|
large: 480,
|
|
|
|
hd720: 720,
|
|
|
|
hd1080: 1080,
|
|
|
|
highres: 1080
|
|
|
|
}[USEROPTS.default_quality];
|
|
|
|
}
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
autoplay: 1,
|
|
|
|
wmode: USEROPTS.wmode_transparent ? "transparent" : "opaque",
|
|
|
|
quality: q,
|
|
|
|
logo: 0
|
|
|
|
};
|
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player = DM.player("ytapiplayer", {
|
|
|
|
video: data.id,
|
2013-08-06 02:55:11 +00:00
|
|
|
width: parseInt(VWIDTH, 10),
|
|
|
|
height: parseInt(VHEIGHT, 10),
|
2014-05-16 05:36:33 +00:00
|
|
|
params: params
|
2013-08-05 04:19:10 +00:00
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.addEventListener("apiready", function (e) {
|
|
|
|
self.player.addEventListener("ended", function (e) {
|
|
|
|
if(CLIENT.leader) {
|
2013-07-28 14:49:12 +00:00
|
|
|
socket.emit("playNext");
|
2013-08-05 04:19:10 +00:00
|
|
|
}
|
2013-07-28 14:49:12 +00:00
|
|
|
});
|
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.addEventListener("pause", function (e) {
|
2013-07-28 14:49:12 +00:00
|
|
|
PLAYER.paused = true;
|
2013-08-05 04:19:10 +00:00
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
2013-07-28 14:49:12 +00:00
|
|
|
});
|
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.addEventListener("playing", function (e) {
|
2013-07-28 14:49:12 +00:00
|
|
|
PLAYER.paused = false;
|
2013-08-05 04:19:10 +00:00
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
2014-02-03 02:04:50 +00:00
|
|
|
if (!self.volumeIsSet) {
|
|
|
|
try {
|
|
|
|
self.setVolume(VOLUME);
|
|
|
|
self.volumeIsSet = true;
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2013-07-28 14:49:12 +00:00
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
});
|
2013-08-05 04:19:10 +00:00
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.load = function (data) {
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2014-02-03 02:04:50 +00:00
|
|
|
if (self.player && self.player.api) {
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.api("load", data.id);
|
2014-02-03 02:04:50 +00:00
|
|
|
}
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.pause = function () {
|
|
|
|
if(self.player && self.player.api)
|
|
|
|
self.player.api("pause");
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.play = function () {
|
|
|
|
if(self.player && self.player.api)
|
|
|
|
self.player.api("play");
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.getTime = function (callback) {
|
|
|
|
if(self.player)
|
|
|
|
callback(self.player.currentTime);
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.seek = function (seconds) {
|
|
|
|
if(self.player && self.player.api)
|
|
|
|
self.player.api("seek", seconds);
|
|
|
|
};
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function (cb) {
|
|
|
|
if (self.player) {
|
2014-12-04 21:55:15 +00:00
|
|
|
var volume = self.player.muted ? 0 : self.player.volume;
|
|
|
|
/*
|
|
|
|
* If the volume was changed by the UI slider, it will be in the range
|
|
|
|
* [0, 100], otherwise if it was only set by the API, it will be in [0, 1].
|
|
|
|
*/
|
|
|
|
if (volume > 1) volume /= 100.0;
|
|
|
|
|
|
|
|
cb(volume);
|
2014-02-03 02:04:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.setVolume = function (vol) {
|
|
|
|
if (self.player && self.player.api) {
|
|
|
|
self.player.api("volume", vol);
|
|
|
|
}
|
|
|
|
};
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
var SoundcloudPlayer = function (data) {
|
|
|
|
var self = this;
|
2014-02-03 02:04:50 +00:00
|
|
|
// The getVolume function on their widget throws TypeErrors
|
|
|
|
// Go figure
|
|
|
|
self.soundcloudIsSeriouslyFuckingBroken = VOLUME;
|
2013-08-05 04:19:10 +00:00
|
|
|
self.videoId = data.id;
|
2015-01-11 18:10:09 +00:00
|
|
|
self.scuri = data.meta.scuri || self.videoId;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-05 04:19:10 +00:00
|
|
|
waitUntilDefined(window, "SC", function () {
|
|
|
|
unfixSoundcloudShit();
|
|
|
|
var iframe = $("<iframe/>");
|
2014-11-12 01:48:08 +00:00
|
|
|
removeOld();
|
|
|
|
iframe.appendTo($("#ytapiplayer"));
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2014-11-12 01:48:08 +00:00
|
|
|
iframe.attr("id", "scplayer");
|
2015-01-11 18:10:09 +00:00
|
|
|
iframe.attr("src", "https://w.soundcloud.com/player/?url="+self.scuri);
|
2014-11-12 01:48:08 +00:00
|
|
|
iframe.css("height", "166px");
|
2013-08-05 04:19:10 +00:00
|
|
|
iframe.css("border", "none");
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-07 18:25:08 +00:00
|
|
|
var volslider = $("<div/>").attr("id", "sc_volume")
|
2014-11-12 01:48:08 +00:00
|
|
|
.css("top", "170px")
|
2013-08-07 18:25:08 +00:00
|
|
|
.insertAfter(iframe);
|
|
|
|
|
|
|
|
volslider.slider({
|
|
|
|
range: "min",
|
2014-02-03 02:04:50 +00:00
|
|
|
value: VOLUME * 100,
|
2013-08-07 18:25:08 +00:00
|
|
|
stop: function (event, ui) {
|
2014-08-04 05:50:24 +00:00
|
|
|
self.player.setVolume(ui.value / 100);
|
2014-02-03 02:04:50 +00:00
|
|
|
self.soundcloudIsSeriouslyFuckingBroken = ui.value / 100;
|
2013-08-07 18:25:08 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-12 01:48:08 +00:00
|
|
|
self.player = SC.Widget("scplayer");
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.bind(SC.Widget.Events.READY, function () {
|
2015-01-11 18:10:09 +00:00
|
|
|
self.player.load(self.scuri, { auto_play: true });
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.bind(SC.Widget.Events.PAUSE, function () {
|
|
|
|
PLAYER.paused = true;
|
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2014-02-03 02:04:50 +00:00
|
|
|
self.player.bind(SC.Widget.Events.FINISH, function () {
|
|
|
|
if(CLIENT.leader) {
|
|
|
|
socket.emit("playNext");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.player.bind(SC.Widget.Events.PLAY, function () {
|
|
|
|
PLAYER.paused = false;
|
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2014-02-03 02:04:50 +00:00
|
|
|
// THAT'S RIGHT, YOU CAN'T SET THE VOLUME BEFORE IT STARTS PLAYING
|
|
|
|
var soundcloudNeedsToFuckingFixTheirPlayer = function () {
|
|
|
|
self.setVolume(VOLUME);
|
|
|
|
self.player.unbind(SC.Widget.Events.PLAY_PROGRESS);
|
|
|
|
};
|
|
|
|
self.player.bind(SC.Widget.Events.PLAY_PROGRESS, soundcloudNeedsToFuckingFixTheirPlayer);
|
2013-08-05 04:19:10 +00:00
|
|
|
}.bind(self));
|
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.load = function (data) {
|
|
|
|
self.videoId = data.id;
|
2015-01-11 18:10:09 +00:00
|
|
|
self.scuri = data.meta.scuri || self.videoId;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2014-02-03 02:04:50 +00:00
|
|
|
if(self.player && self.player.load) {
|
2015-01-11 18:10:09 +00:00
|
|
|
self.player.load(self.scuri, { auto_play: true });
|
2014-02-03 02:04:50 +00:00
|
|
|
var soundcloudNeedsToFuckingFixTheirPlayer = function () {
|
|
|
|
self.setVolume(VOLUME);
|
|
|
|
self.player.unbind(SC.Widget.Events.PLAY_PROGRESS);
|
|
|
|
};
|
|
|
|
self.player.bind(SC.Widget.Events.PLAY_PROGRESS, soundcloudNeedsToFuckingFixTheirPlayer);
|
|
|
|
}
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.pause = function () {
|
|
|
|
if(self.player && self.player.pause)
|
|
|
|
self.player.pause();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.play = function () {
|
|
|
|
if(self.player && self.player.play)
|
|
|
|
self.player.play();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.getTime = function (callback) {
|
|
|
|
if(self.player && self.player.getPosition) {
|
|
|
|
self.player.getPosition(function (pos) {
|
|
|
|
callback(pos / 1000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-05 04:19:10 +00:00
|
|
|
self.seek = function (seconds) {
|
|
|
|
if(self.player && self.player.seekTo)
|
|
|
|
self.player.seekTo(seconds * 1000);
|
|
|
|
};
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function (cb) {
|
|
|
|
cb(self.soundcloudIsSeriouslyFuckingBroken);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.setVolume = function (vol) {
|
2014-08-04 05:56:17 +00:00
|
|
|
self.player.setVolume(vol);
|
2014-02-03 02:04:50 +00:00
|
|
|
};
|
2013-08-05 04:19:10 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
var LivestreamPlayer = function (data) {
|
|
|
|
removeOld();
|
|
|
|
var self = this;
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init = function () {
|
|
|
|
var flashvars = { channel: self.videoId };
|
|
|
|
var params = { AllowScriptAccess: "always" };
|
2013-09-10 22:18:02 +00:00
|
|
|
var prto = location.protocol;
|
2013-08-06 02:46:56 +00:00
|
|
|
swfobject.embedSWF(
|
2013-09-10 22:18:02 +00:00
|
|
|
prto+"//cdn.livestream.com/chromelessPlayer/v20/playerapi.swf",
|
2013-08-06 02:46:56 +00:00
|
|
|
"ytapiplayer",
|
|
|
|
VWIDTH, VHEIGHT,
|
|
|
|
"9.0.0",
|
|
|
|
"expressInstall.swf",
|
|
|
|
flashvars,
|
|
|
|
params
|
|
|
|
);
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.load = function(data) {
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.pause = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.play = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.getTime = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.seek = function () { };
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function () { };
|
|
|
|
|
|
|
|
self.setVolume = function () { };
|
|
|
|
|
2014-02-24 05:27:07 +00:00
|
|
|
waitUntilDefined(window, "swfobject", function () {
|
|
|
|
self.init();
|
|
|
|
});
|
2013-08-06 02:55:11 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
var TwitchTVPlayer = function (data) {
|
|
|
|
removeOld();
|
|
|
|
var self = this;
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init = function () {
|
2014-11-25 01:24:47 +00:00
|
|
|
var url = "https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?channel="+self.videoId;
|
2013-08-06 02:46:56 +00:00
|
|
|
var params = {
|
|
|
|
allowFullScreen: "true",
|
|
|
|
allowScriptAccess: "always",
|
|
|
|
allowNetworking: "all",
|
2014-11-25 01:24:47 +00:00
|
|
|
movie: "https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf",
|
2013-08-06 02:46:56 +00:00
|
|
|
id: "live_embed_player_flash",
|
2014-02-03 02:04:50 +00:00
|
|
|
flashvars: "hostname=www.twitch.tv&channel="+self.videoId+"&auto_play=true&start_volume=" + VOLUME
|
2013-08-06 02:46:56 +00:00
|
|
|
};
|
|
|
|
swfobject.embedSWF(url,
|
|
|
|
"ytapiplayer",
|
|
|
|
VWIDTH, VHEIGHT,
|
2014-02-03 02:04:50 +00:00
|
|
|
"8",
|
2013-08-06 02:46:56 +00:00
|
|
|
null, null,
|
|
|
|
params,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.load = function (data) {
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.pause = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.play = function () { };
|
2013-07-12 20:34:55 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.getTime = function () { };
|
|
|
|
|
|
|
|
self.seek = function () { };
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function () { };
|
|
|
|
|
|
|
|
self.setVolume = function () { };
|
|
|
|
|
|
|
|
waitUntilDefined(window, "swfobject", function () {
|
|
|
|
self.init();
|
|
|
|
});
|
2013-08-06 02:55:11 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2014-02-03 02:04:50 +00:00
|
|
|
function rtmpEventHandler(id, ev, data) {
|
|
|
|
if (ev === "volumechange") {
|
|
|
|
PLAYER.volume = (data.muted ? 0 : data.volume);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
var RTMPPlayer = function (data) {
|
|
|
|
removeOld();
|
2014-02-03 02:04:50 +00:00
|
|
|
var self =this;
|
|
|
|
self.volume = VOLUME;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init = function () {
|
2013-09-10 22:18:02 +00:00
|
|
|
var prto = location.protocol;
|
|
|
|
var url = prto+"//fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf";
|
2013-08-06 02:46:56 +00:00
|
|
|
var src = encodeURIComponent(self.videoId);
|
|
|
|
var params = {
|
|
|
|
allowFullScreen: "true",
|
|
|
|
allowScriptAccess: "always",
|
|
|
|
allowNetworking: "all",
|
|
|
|
wMode: "direct",
|
2013-09-10 22:18:02 +00:00
|
|
|
movie: prto+"//fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf",
|
2014-02-03 02:04:50 +00:00
|
|
|
flashvars: "src="+src+"&streamType=live&javascriptCallbackFunction=rtmpEventHandler&autoPlay=true&volume=" + VOLUME
|
2013-06-11 15:29:21 +00:00
|
|
|
};
|
2013-08-06 02:46:56 +00:00
|
|
|
swfobject.embedSWF(url,
|
|
|
|
"ytapiplayer",
|
|
|
|
VWIDTH, VHEIGHT,
|
|
|
|
"8",
|
|
|
|
null, null,
|
|
|
|
params,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.load = function (data) {
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.pause = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.play = function () { };
|
2013-07-12 20:34:55 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.getTime = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.seek = function () { };
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function (cb) {
|
|
|
|
cb(self.volume);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.setVolume = function () { };
|
|
|
|
|
|
|
|
waitUntilDefined(window, "swfobject", function () {
|
|
|
|
self.init();
|
|
|
|
});
|
2013-08-06 02:55:11 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
var JWPlayer = function (data) {
|
|
|
|
var self = this;
|
|
|
|
self.videoId = data.id;
|
2014-02-03 02:04:50 +00:00
|
|
|
if (data.url) {
|
|
|
|
self.videoURL = data.url;
|
|
|
|
} else {
|
|
|
|
self.videoURL = data.id;
|
|
|
|
}
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init = function () {
|
|
|
|
removeOld();
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
jwplayer("ytapiplayer").setup({
|
2014-02-03 02:04:50 +00:00
|
|
|
file: self.videoURL,
|
2014-11-14 02:24:05 +00:00
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
2014-09-07 03:59:28 +00:00
|
|
|
autostart: true,
|
|
|
|
type: data.contentType
|
2013-08-06 02:46:56 +00:00
|
|
|
});
|
2014-09-07 03:59:28 +00:00
|
|
|
|
2014-11-14 02:24:05 +00:00
|
|
|
jwplayer().onReady(function() {
|
|
|
|
$("#ytapiplayer").addClass("embed-responsive-item");
|
2014-12-03 04:21:52 +00:00
|
|
|
if ($("#ytapiplayer")[0].tagName === "OBJECT") {
|
|
|
|
$("#ytapiplayer").parent().css("position", "absolute");
|
|
|
|
}
|
2014-11-14 02:24:05 +00:00
|
|
|
handleVideoResize();
|
|
|
|
});
|
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
jwplayer().onPlay(function() {
|
2014-12-03 04:21:52 +00:00
|
|
|
/* Somehow JWPlayer manages to have THE SAME PROBLEM AS SOUNDCLOUD.
|
|
|
|
* It seems to be impossible to set the volume before the video has
|
|
|
|
* started playing. How this is so damn difficult to get right I will
|
|
|
|
* never understand.
|
|
|
|
*/
|
|
|
|
self.setVolume(VOLUME);
|
2013-08-06 02:46:56 +00:00
|
|
|
self.paused = false;
|
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
|
|
|
});
|
|
|
|
jwplayer().onPause(function() {
|
|
|
|
self.paused = true;
|
|
|
|
if(CLIENT.leader)
|
|
|
|
sendVideoUpdate();
|
|
|
|
});
|
|
|
|
jwplayer().onComplete(function() {
|
|
|
|
socket.emit("playNext");
|
|
|
|
});
|
2013-08-06 02:55:11 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.load = function (data) {
|
|
|
|
self.videoId = data.id;
|
2014-11-14 02:24:05 +00:00
|
|
|
if (data.url) {
|
|
|
|
self.videoURL = data.url;
|
|
|
|
} else {
|
|
|
|
self.videoURL = data.id;
|
|
|
|
}
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.pause = function () {
|
|
|
|
if(jwplayer)
|
|
|
|
jwplayer().pause(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.play = function () {
|
|
|
|
if(jwplayer)
|
|
|
|
jwplayer().play(true);
|
|
|
|
};
|
2013-07-12 20:34:55 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.getTime = function (callback) {
|
2013-06-11 15:29:21 +00:00
|
|
|
// Only return time for non-live media
|
2013-08-06 02:46:56 +00:00
|
|
|
if(jwplayer && jwplayer().getDuration() != -1) {
|
2013-06-11 15:29:21 +00:00
|
|
|
callback(jwplayer().getPosition());
|
|
|
|
}
|
2013-08-06 02:46:56 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.seek = function (time) {
|
|
|
|
if(jwplayer)
|
|
|
|
jwplayer().seek(time);
|
|
|
|
};
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function (cb) {
|
|
|
|
cb(jwplayer().getVolume() / 100);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.setVolume = function (vol) {
|
|
|
|
jwplayer().setVolume(vol * 100);
|
|
|
|
};
|
|
|
|
|
|
|
|
waitUntilDefined(window, "jwplayer", function () { self.init(); });
|
2013-08-06 02:55:11 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
var UstreamPlayer = function (data) {
|
|
|
|
var self = this;
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init = function () {
|
|
|
|
var iframe = $("<iframe/>");
|
|
|
|
removeOld(iframe);
|
|
|
|
iframe.attr("width", VWIDTH);
|
|
|
|
iframe.attr("height", VHEIGHT);
|
2014-11-12 01:48:08 +00:00
|
|
|
iframe.attr("src", "//www.ustream.tv/embed/"+self.videoId+"?v=3&wmode=direct");
|
2013-08-06 02:46:56 +00:00
|
|
|
iframe.attr("frameborder", "0");
|
|
|
|
iframe.attr("scrolling", "no");
|
|
|
|
iframe.css("border", "none");
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.load = function (data) {
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init();
|
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.pause = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.play = function () { };
|
2013-07-12 20:34:55 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.getTime = function () { };
|
|
|
|
|
|
|
|
self.seek = function () { };
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function () { };
|
|
|
|
|
|
|
|
self.setVolume = function () { };
|
|
|
|
|
|
|
|
self.init();
|
2013-08-06 02:55:11 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
var ImgurPlayer = function (data) {
|
|
|
|
var self = this;
|
|
|
|
self.init = function () {
|
|
|
|
var iframe = $("<iframe/>");
|
|
|
|
removeOld(iframe);
|
|
|
|
iframe.attr("width", VWIDTH);
|
|
|
|
iframe.attr("height", VHEIGHT);
|
2013-09-10 22:18:02 +00:00
|
|
|
var prto = location.protocol;
|
|
|
|
iframe.attr("src", prto+"//imgur.com/a/"+self.videoId+"/embed");
|
2013-08-06 02:46:56 +00:00
|
|
|
iframe.attr("frameborder", "0");
|
|
|
|
iframe.attr("scrolling", "no");
|
|
|
|
iframe.css("border", "none");
|
|
|
|
};
|
|
|
|
|
|
|
|
self.load = function (data) {
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:55:11 +00:00
|
|
|
self.init();
|
2013-08-06 02:46:56 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.pause = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.play = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.getTime = function () { };
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.seek = function () { };
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function () { };
|
|
|
|
|
|
|
|
self.setVolume = function () { };
|
|
|
|
|
|
|
|
self.init();
|
2013-08-06 02:55:11 +00:00
|
|
|
};
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
var CustomPlayer = function (data) {
|
|
|
|
var self = this;
|
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:46:56 +00:00
|
|
|
self.init = function () {
|
|
|
|
removeOld();
|
|
|
|
var div = $("#ytapiplayer");
|
|
|
|
div.attr("id", "");
|
2014-12-11 05:56:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 2014-12-10
|
|
|
|
*
|
|
|
|
* If a user is connected via HTTPS and the custom link is
|
|
|
|
* HTTP, then the embed fails due to mixed active content
|
|
|
|
* policy. Display a message indicating this.
|
|
|
|
*/
|
|
|
|
if (location.protocol.match(/^https/) &&
|
|
|
|
self.videoId.match(/http:/)) {
|
|
|
|
|
|
|
|
div.html("You are currently connected via HTTPS but " +
|
|
|
|
"the custom embed link uses non-secure HTTP. " +
|
|
|
|
"Your browser may therefore block it from loading. " +
|
|
|
|
"To fix this, either add the custom embed as a secure " +
|
|
|
|
"URL (https://...) if the source supports it, or " +
|
|
|
|
"visit this page over plain HTTP (your websocket will still " +
|
|
|
|
"use secure HTTPS for communication, just the page " +
|
|
|
|
"will load over plain HTTP).");
|
|
|
|
|
|
|
|
// Try to salvage the link
|
|
|
|
self.videoId = self.videoId.replace(/http:/g, "https:");
|
|
|
|
}
|
2013-08-06 02:46:56 +00:00
|
|
|
div.append(self.videoId);
|
|
|
|
|
2013-08-06 02:55:11 +00:00
|
|
|
self.player = div.find("iframe");
|
2013-08-06 02:46:56 +00:00
|
|
|
if(self.player.length === 0) self.player = div.find("object");
|
|
|
|
if(self.player.length === 0) self.player = div;
|
|
|
|
self.player.attr("id", "ytapiplayer");
|
|
|
|
self.player.attr("width", VWIDTH);
|
|
|
|
self.player.attr("height", VHEIGHT);
|
|
|
|
};
|
2013-08-03 15:12:53 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.load = function (data) {
|
2013-08-06 04:07:54 +00:00
|
|
|
self.videoId = data.id;
|
2013-09-27 02:43:38 +00:00
|
|
|
self.videoLength = data.seconds;
|
2013-08-06 02:55:11 +00:00
|
|
|
self.init();
|
2013-08-06 02:46:56 +00:00
|
|
|
};
|
2013-08-03 15:12:53 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.pause = function () { };
|
2013-08-03 15:12:53 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.play = function () { };
|
2013-08-03 15:12:53 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
self.getTime = function () { };
|
|
|
|
|
|
|
|
self.seek = function () { };
|
2014-02-03 02:04:50 +00:00
|
|
|
|
|
|
|
self.getVolume = function () { };
|
|
|
|
|
|
|
|
self.setVolume = function () { };
|
|
|
|
|
|
|
|
self.init();
|
2013-08-06 02:46:56 +00:00
|
|
|
};
|
2013-08-03 15:12:53 +00:00
|
|
|
|
2014-06-01 17:54:53 +00:00
|
|
|
function FilePlayer(data) {
|
2014-02-03 02:04:50 +00:00
|
|
|
var self = this;
|
2014-06-01 17:54:53 +00:00
|
|
|
|
2014-02-03 02:04:50 +00:00
|
|
|
self.init = function (data) {
|
2014-07-12 03:42:13 +00:00
|
|
|
if (!data.url) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-03 02:04:50 +00:00
|
|
|
self.videoId = data.id;
|
|
|
|
self.videoURL = data.url;
|
2014-06-06 04:58:26 +00:00
|
|
|
var isAudio = data.meta.codec && data.meta.codec.match(/^mp3$|^vorbis$/);
|
|
|
|
var video;
|
|
|
|
if (isAudio) {
|
|
|
|
video = $("<audio/>");
|
|
|
|
} else {
|
|
|
|
video = $("<video/>")
|
|
|
|
}
|
|
|
|
video
|
2014-12-03 04:21:52 +00:00
|
|
|
.addClass("embed-responsive-item")
|
2014-02-03 02:04:50 +00:00
|
|
|
.attr("src", self.videoURL)
|
|
|
|
.attr("controls", "controls")
|
|
|
|
.attr("id", "#ytapiplayer")
|
|
|
|
.attr("width", VWIDTH)
|
|
|
|
.attr("height", VHEIGHT)
|
2014-12-03 04:21:52 +00:00
|
|
|
.attr("autoplay", true)
|
2014-02-03 02:04:50 +00:00
|
|
|
.html("Your browser does not support HTML5 <code><video></code> tags :(");
|
2014-03-08 02:37:20 +00:00
|
|
|
video.error(function (err) {
|
|
|
|
setTimeout(function () {
|
2014-06-01 17:54:53 +00:00
|
|
|
console.log("<video> tag failed, falling back to Flash");
|
2014-12-03 04:21:52 +00:00
|
|
|
console.log(err);
|
2014-08-18 17:00:26 +00:00
|
|
|
PLAYER = new JWPlayer(data);
|
|
|
|
PLAYER.type = "jw";
|
2014-03-08 02:37:20 +00:00
|
|
|
}, 100);
|
|
|
|
});
|
2014-02-03 02:04:50 +00:00
|
|
|
removeOld(video);
|
|
|
|
self.player = video[0];
|
2014-08-08 03:34:24 +00:00
|
|
|
if (!Object.hasOwnProperty.call(self, "paused")) {
|
|
|
|
Object.defineProperty(self, "paused", {
|
|
|
|
get: function () {
|
|
|
|
return self.player.paused;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
self.player.onpause = function () {
|
|
|
|
self.paused = true;
|
|
|
|
if (CLIENT.leader) {
|
|
|
|
sendVideoUpdate();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
self.player.onplay = function () {
|
|
|
|
self.paused = false;
|
|
|
|
if (CLIENT.leader) {
|
|
|
|
sendVideoUpdate();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
self.player.onended = function () {
|
|
|
|
if (CLIENT.leader) {
|
|
|
|
socket.emit("playNext");
|
|
|
|
}
|
|
|
|
};
|
2014-02-03 02:04:50 +00:00
|
|
|
self.setVolume(VOLUME);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.load = function (data) {
|
2014-06-06 04:58:26 +00:00
|
|
|
if (data.forceFlash) {
|
|
|
|
self.initFlash(data);
|
|
|
|
} else {
|
|
|
|
self.init(data);
|
|
|
|
}
|
2014-02-03 02:04:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
self.pause = function () {
|
|
|
|
if (self.player) {
|
|
|
|
self.player.pause();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.play = function () {
|
|
|
|
if (self.player) {
|
|
|
|
self.player.play();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.getTime = function (callback) {
|
|
|
|
if (self.player) {
|
|
|
|
callback(self.player.currentTime);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.seek = function (time) {
|
|
|
|
if (self.player) {
|
2014-06-01 17:54:53 +00:00
|
|
|
try {
|
|
|
|
self.player.currentTime = time;
|
|
|
|
} catch (e) {
|
|
|
|
}
|
2014-02-03 02:04:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.getVolume = function (cb) {
|
|
|
|
if (self.player) {
|
|
|
|
if (self.player.muted) {
|
|
|
|
cb(0);
|
|
|
|
} else {
|
|
|
|
cb(self.player.volume);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.setVolume = function (vol) {
|
|
|
|
if (self.player) {
|
|
|
|
self.player.volume = vol;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-01 17:54:53 +00:00
|
|
|
if (data.forceFlash) {
|
2014-08-18 17:00:26 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
PLAYER = new JWPlayer(data);
|
|
|
|
PLAYER.type = "jw";
|
|
|
|
}, 1);
|
2014-06-01 17:54:53 +00:00
|
|
|
} else {
|
|
|
|
self.init(data);
|
|
|
|
}
|
2014-02-03 02:04:50 +00:00
|
|
|
};
|
|
|
|
|
2015-01-23 05:21:31 +00:00
|
|
|
var HitboxPlayer = function (data) {
|
|
|
|
var self = this;
|
|
|
|
self.videoId = data.id;
|
|
|
|
self.videoLength = data.seconds;
|
|
|
|
self.init = function () {
|
|
|
|
if (location.protocol.match(/^https/)) {
|
|
|
|
var div = makeAlert("Security Policy",
|
|
|
|
"You are currently connected via HTTPS but " +
|
|
|
|
"Hitbox only supports plain HTTP. Due to browser " +
|
|
|
|
"security policy, the embed player cannot be loaded. " +
|
|
|
|
"In order to watch the video, you must visit this page " +
|
|
|
|
"from its plain HTTP URL (your websocket will still be " +
|
|
|
|
"secured with HTTPS). Please complain to Hitbox about this.",
|
|
|
|
"alert-danger");
|
|
|
|
div.addClass("embed-responsive-item");
|
|
|
|
removeOld(div);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var iframe = $("<iframe/>")
|
|
|
|
.attr("src", "http://hitbox.tv/embed/" + self.videoId)
|
|
|
|
.attr("webkitAllowFullScreen", "")
|
|
|
|
.attr("mozallowfullscreen", "")
|
|
|
|
.attr("allowFullScreen", "");
|
|
|
|
|
|
|
|
if (USEROPTS.wmode_transparent)
|
|
|
|
iframe.attr("wmode", "transparent");
|
|
|
|
|
|
|
|
removeOld(iframe);
|
|
|
|
self.player = iframe;
|
|
|
|
};
|
|
|
|
|
|
|
|
self.load = function (data) {
|
|
|
|
self.videoId = data.id;
|
|
|
|
self.videoLength = data.seconds;
|
|
|
|
self.init();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.pause = function () { };
|
|
|
|
|
|
|
|
self.play = function () { };
|
|
|
|
|
|
|
|
self.getTime = function () { };
|
|
|
|
|
|
|
|
self.seek = function () { };
|
|
|
|
|
|
|
|
self.getVolume = function () { };
|
|
|
|
|
|
|
|
self.setVolume = function () { };
|
|
|
|
|
|
|
|
self.init();
|
|
|
|
};
|
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
function handleMediaUpdate(data) {
|
2013-09-27 02:43:38 +00:00
|
|
|
// Don't update if the position is past the video length, but
|
|
|
|
// make an exception when the video length is 0 seconds
|
|
|
|
if (typeof PLAYER.videoLength === "number") {
|
2014-02-03 02:04:50 +00:00
|
|
|
if (PLAYER.videoLength > 0 &&
|
2013-09-27 02:43:38 +00:00
|
|
|
data.currentTime > PLAYER.videoLength) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-09-22 04:54:29 +00:00
|
|
|
var wait = data.currentTime < 0;
|
2013-08-06 02:46:56 +00:00
|
|
|
// Media change
|
|
|
|
if(data.id && data.id !== PLAYER.videoId) {
|
|
|
|
if(data.currentTime < 0)
|
2013-06-11 15:29:21 +00:00
|
|
|
data.currentTime = 0;
|
2013-08-06 02:46:56 +00:00
|
|
|
PLAYER.load(data);
|
|
|
|
PLAYER.play();
|
2013-06-11 15:29:21 +00:00
|
|
|
}
|
2013-09-22 04:54:29 +00:00
|
|
|
|
|
|
|
if (wait) {
|
2013-10-17 02:50:31 +00:00
|
|
|
/* Stupid hack -- In this thrilling episode of
|
|
|
|
"the YouTube API developers should eat a boat", the
|
|
|
|
HTML5 player apparently breaks if I play()-seek(0)-pause()
|
|
|
|
quickly (as a "start buffering but don't play yet"
|
|
|
|
mechanism)
|
2014-05-10 01:09:17 +00:00
|
|
|
|
|
|
|
Addendum 2014-05-09
|
|
|
|
Made this slightly less hacky by waiting for a PLAYING event
|
|
|
|
to fire instead of just waiting 500ms and assuming that's
|
|
|
|
long enough
|
2013-10-17 02:50:31 +00:00
|
|
|
*/
|
|
|
|
if (PLAYER.type === "yt") {
|
2014-05-10 01:09:17 +00:00
|
|
|
PLAYER.theYouTubeDevsNeedToFixThisShit = true;
|
|
|
|
} else {
|
2013-10-17 02:50:31 +00:00
|
|
|
PLAYER.seek(0);
|
|
|
|
PLAYER.pause();
|
2014-05-10 01:09:17 +00:00
|
|
|
}
|
2013-09-22 04:54:29 +00:00
|
|
|
return;
|
2014-05-10 08:01:09 +00:00
|
|
|
} else if (PLAYER.type === "yt") {
|
|
|
|
PLAYER.theYouTubeDevsNeedToFixThisShit = false;
|
2013-09-22 04:54:29 +00:00
|
|
|
}
|
2014-02-03 02:04:50 +00:00
|
|
|
|
2013-08-06 02:46:56 +00:00
|
|
|
// Don't synch if leader or synch disabled
|
|
|
|
if(CLIENT.leader || !USEROPTS.synch)
|
2013-06-11 15:29:21 +00:00
|
|
|
return;
|
2013-08-06 02:46:56 +00:00
|
|
|
|
|
|
|
// Handle pause/unpause
|
2013-06-11 15:29:21 +00:00
|
|
|
if(data.paused) {
|
2014-08-08 03:34:24 +00:00
|
|
|
if (!PLAYER.paused) {
|
|
|
|
PLAYER.seek(data.currentTime);
|
|
|
|
PLAYER.pause();
|
|
|
|
}
|
2013-08-06 02:55:11 +00:00
|
|
|
} else {
|
2014-08-08 03:34:24 +00:00
|
|
|
if (PLAYER.paused) {
|
|
|
|
PLAYER.play();
|
|
|
|
}
|
2013-06-11 15:29:21 +00:00
|
|
|
}
|
2013-08-06 02:46:56 +00:00
|
|
|
|
|
|
|
// Handle time change
|
|
|
|
PLAYER.getTime(function (seconds) {
|
2013-06-11 15:29:21 +00:00
|
|
|
var time = data.currentTime;
|
|
|
|
var diff = time - seconds || time;
|
2013-10-24 22:31:04 +00:00
|
|
|
var acc = USEROPTS.sync_accuracy;
|
|
|
|
// Dailymotion can't seek more accurately than to the nearest
|
|
|
|
// 2 seconds. It gets stuck looping portions of the video
|
|
|
|
// at the default synch accuracy of 2.
|
|
|
|
// I've found 5 works decently.
|
|
|
|
if (PLAYER.type === "dm")
|
|
|
|
acc = Math.max(acc, 5.0);
|
|
|
|
|
|
|
|
if(diff > acc) {
|
2013-08-06 02:46:56 +00:00
|
|
|
PLAYER.seek(time);
|
2013-10-24 22:31:04 +00:00
|
|
|
} else if(diff < -acc) {
|
2013-08-06 02:46:56 +00:00
|
|
|
// Don't synch all the way back, causes buffering problems
|
|
|
|
// because for some dumb reason YouTube erases the buffer
|
|
|
|
// when you seek backwards
|
2013-10-24 22:31:04 +00:00
|
|
|
//
|
|
|
|
// ADDENDUM 2013-10-24 Except for dailymotion because
|
|
|
|
// their player is inaccurate
|
|
|
|
if (PLAYER.type !== "dm")
|
|
|
|
time += 1;
|
|
|
|
PLAYER.seek(time);
|
2013-06-11 15:29:21 +00:00
|
|
|
}
|
2013-08-06 02:46:56 +00:00
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
}
|
2013-08-06 03:25:16 +00:00
|
|
|
|
|
|
|
var constructors = {
|
|
|
|
"yt": YouTubePlayer,
|
|
|
|
"vi": VIMEO_FLASH ? VimeoFlashPlayer : VimeoPlayer,
|
|
|
|
"dm": DailymotionPlayer,
|
|
|
|
"sc": SoundcloudPlayer,
|
|
|
|
"li": LivestreamPlayer,
|
|
|
|
"tw": TwitchTVPlayer,
|
|
|
|
"us": UstreamPlayer,
|
2013-08-06 03:55:46 +00:00
|
|
|
"jw": JWPlayer,
|
2013-08-06 03:25:16 +00:00
|
|
|
"im": ImgurPlayer,
|
2013-11-07 23:19:36 +00:00
|
|
|
"cu": CustomPlayer,
|
2014-08-18 17:00:26 +00:00
|
|
|
"rt": RTMPPlayer,
|
2014-06-01 17:54:53 +00:00
|
|
|
"rv": FilePlayer,
|
2015-01-23 05:21:31 +00:00
|
|
|
"fi": FilePlayer,
|
|
|
|
"hb": HitboxPlayer
|
2013-08-06 03:25:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function loadMediaPlayer(data) {
|
|
|
|
if(data.type in constructors) {
|
|
|
|
PLAYER = new constructors[data.type](data);
|
|
|
|
PLAYER.type = data.type;
|
|
|
|
}
|
|
|
|
}
|