Use JWPlayer as flash fallback because it can actually synch

This commit is contained in:
calzoneman 2014-08-18 12:00:26 -05:00
parent 6452ea4ab4
commit aff20c3012
5 changed files with 7 additions and 147 deletions

View File

@ -73,10 +73,6 @@ mixin us-playback
.col-sm-4 .col-sm-4
.col-sm-8 .col-sm-8
p.text-info Setting <code>wmode=transparent</code> allows objects to be displayed above the video player, but may cause performance issues on some systems. p.text-info Setting <code>wmode=transparent</code> allows objects to be displayed above the video player, but may cause performance issues on some systems.
mixin rcheckbox("us-no-h264", "Use flash for h.264 playback")
.col-sm-4
.col-sm-8
p.text-info CyTube will attempt to autodetect browsers that do not natively support h.264 playback and fall back on a flash player. This overrides that automatic detection and forces use of the flash player.
mixin rcheckbox("us-hidevideo", "Remove the video player") mixin rcheckbox("us-hidevideo", "Remove the video player")
mixin rcheckbox("us-playlistbuttons", "Hide playlist buttons by default") mixin rcheckbox("us-playlistbuttons", "Hide playlist buttons by default")
mixin rcheckbox("us-oldbtns", "Old style playlist buttons") mixin rcheckbox("us-oldbtns", "Old style playlist buttons")

View File

@ -867,10 +867,6 @@ Callbacks = {
} }
if (data.type === "fi") { if (data.type === "fi") {
if (USEROPTS.no_h264 && data.meta.codec === "mov/h264") {
data.forceFlash = true;
}
data.url = data.id; data.url = data.id;
} }
@ -885,13 +881,6 @@ Callbacks = {
data = googlePlusSimulator2014(data); data = googlePlusSimulator2014(data);
} }
/* RTMP player has been replaced with the general flash player */
if (data.type === "rt") {
data.url = data.id;
data.type = "fi";
data.forceFlash = true;
}
if (data.type != PLAYER.type) { if (data.type != PLAYER.type) {
loadMediaPlayer(data); loadMediaPlayer(data);
} }

View File

@ -103,19 +103,6 @@ function getOrDefault(k, def) {
return v; return v;
} }
function default_noh264() {
var ua = navigator.userAgent + "";
if (ua.match(/Chrome|Chromium/)) {
return false;
} else if (ua.match(/Firefox/)) {
var version = ua.match(/Firefox\/(\d+)/)[1];
version = parseInt(version);
return version >= 29;
} else {
return true;
}
}
var USEROPTS = { var USEROPTS = {
theme : getOrDefault("theme", "/css/themes/slate.css"), theme : getOrDefault("theme", "/css/themes/slate.css"),
layout : getOrDefault("layout", "fluid"), layout : getOrDefault("layout", "fluid"),
@ -139,7 +126,6 @@ var USEROPTS = {
default_quality : getOrDefault("default_quality", ""), default_quality : getOrDefault("default_quality", ""),
boop : getOrDefault("boop", "never"), boop : getOrDefault("boop", "never"),
secure_connection : getOrDefault("secure_connection", false), secure_connection : getOrDefault("secure_connection", false),
no_h264 : getOrDefault("no_h264", default_noh264()),
show_shadowchat : getOrDefault("show_shadowchat", false) show_shadowchat : getOrDefault("show_shadowchat", false)
}; };

View File

@ -687,34 +687,6 @@ var RTMPPlayer = function (data) {
}); });
}; };
function flashEventHandler(id, ev, data) {
switch (ev) {
case "timeupdate":
PLAYER.currentTime = data.currentTime;
break;
case "pause":
PLAYER.paused = data.paused;
if (CLIENT.leader)
sendVideoUpdate();
break;
case "play":
PLAYER.paused = data.paused;
if (CLIENT.leader)
sendVideoUpdate();
break;
case "volumechange":
PLAYER.volume = (data.muted ? 0 : data.volume);
break;
case "progress":
break;
case "onJavaScriptBridgeCreated":
PLAYER.player = $("#ytapiplayer")[0];
break;
default:
break;
}
}
var JWPlayer = function (data) { var JWPlayer = function (data) {
var self = this; var self = this;
self.videoId = data.id; self.videoId = data.id;
@ -902,85 +874,6 @@ var CustomPlayer = function (data) {
function FilePlayer(data) { function FilePlayer(data) {
var self = this; var self = this;
self.initFlash = function (data) {
waitUntilDefined(window, "swfobject", function () {
if (!data.url) {
return;
}
self.volume = VOLUME;
self.videoId = data.id;
self.videoURL = data.url;
self.videoLength = data.seconds;
self.paused = false;
self.currentTime = 0;
var params = {
allowFullScreen: "true",
allowScriptAccess: "always",
allowNetworking: "all",
wMode: "direct"
};
var flashvars = {
src: encodeURIComponent(self.videoURL),
// For some reason this param seems not to work
clipStartTime: Math.floor(data.currentTime),
javascriptCallbackFunction: "flashEventHandler",
autoPlay: true,
volume: VOLUME
};
if (self.videoURL.indexOf("rtmp") === 0) {
flashvars.streamType = "live";
} else {
flashvars.streamType = "recorded";
}
swfobject.embedSWF("/StrobeMediaPlayback.swf",
"ytapiplayer",
VWIDTH, VHEIGHT,
"10.1.0",
null,
flashvars,
params,
{ name: "ytapiplayer" }
);
self.player = $("#ytapiplayer")[0];
resizeStuff();
self.pause = function () {
if (self.player && self.player.pause)
self.player.pause();
};
self.play = function () {
// Why is it play2? What happened to play1?
if (self.player && self.player.play2)
self.player.play2();
};
self.getTime = function (cb) {
cb(self.currentTime);
};
self.seek = function (to) {
if (self.player && self.player.seek) {
self.player.seek(Math.floor(to));
}
};
self.getVolume = function (cb) {
cb(self.volume);
};
self.setVolume = function (vol) {
if (self.player && self.player.setVolume)
self.player.setVolume(vol);
};
});
};
self.init = function (data) { self.init = function (data) {
if (!data.url) { if (!data.url) {
return; return;
@ -1004,7 +897,8 @@ function FilePlayer(data) {
video.error(function (err) { video.error(function (err) {
setTimeout(function () { setTimeout(function () {
console.log("<video> tag failed, falling back to Flash"); console.log("<video> tag failed, falling back to Flash");
self.initFlash(data); PLAYER = new JWPlayer(data);
PLAYER.type = "jw";
}, 100); }, 100);
}); });
removeOld(video); removeOld(video);
@ -1089,7 +983,10 @@ function FilePlayer(data) {
}; };
if (data.forceFlash) { if (data.forceFlash) {
self.initFlash(data); setTimeout(function () {
PLAYER = new JWPlayer(data);
PLAYER.type = "jw";
}, 1);
} else { } else {
self.init(data); self.init(data);
} }
@ -1191,9 +1088,8 @@ var constructors = {
"jw": JWPlayer, "jw": JWPlayer,
"im": ImgurPlayer, "im": ImgurPlayer,
"cu": CustomPlayer, "cu": CustomPlayer,
"rt": FilePlayer, "rt": RTMPPlayer,
"rv": FilePlayer, "rv": FilePlayer,
"fl": FilePlayer,
"fi": FilePlayer "fi": FilePlayer
}; };

View File

@ -611,7 +611,6 @@ function showUserOptions() {
$("#us-synch").prop("checked", USEROPTS.synch); $("#us-synch").prop("checked", USEROPTS.synch);
$("#us-synch-accuracy").val(USEROPTS.sync_accuracy); $("#us-synch-accuracy").val(USEROPTS.sync_accuracy);
$("#us-wmode-transparent").prop("checked", USEROPTS.wmode_transparent); $("#us-wmode-transparent").prop("checked", USEROPTS.wmode_transparent);
$("#us-no-h264").prop("checked", USEROPTS.no_h264);
$("#us-hidevideo").prop("checked", USEROPTS.hidevid); $("#us-hidevideo").prop("checked", USEROPTS.hidevid);
$("#us-playlistbuttons").prop("checked", USEROPTS.qbtn_hide); $("#us-playlistbuttons").prop("checked", USEROPTS.qbtn_hide);
$("#us-oldbtns").prop("checked", USEROPTS.qbtn_idontlikechange); $("#us-oldbtns").prop("checked", USEROPTS.qbtn_idontlikechange);
@ -645,7 +644,6 @@ function saveUserOptions() {
USEROPTS.synch = $("#us-synch").prop("checked"); USEROPTS.synch = $("#us-synch").prop("checked");
USEROPTS.sync_accuracy = parseFloat($("#us-synch-accuracy").val()) || 2; USEROPTS.sync_accuracy = parseFloat($("#us-synch-accuracy").val()) || 2;
USEROPTS.wmode_transparent = $("#us-wmode-transparent").prop("checked"); USEROPTS.wmode_transparent = $("#us-wmode-transparent").prop("checked");
USEROPTS.no_h264 = $("#us-no-h264").prop("checked");
USEROPTS.hidevid = $("#us-hidevideo").prop("checked"); USEROPTS.hidevid = $("#us-hidevideo").prop("checked");
USEROPTS.qbtn_hide = $("#us-playlistbuttons").prop("checked"); USEROPTS.qbtn_hide = $("#us-playlistbuttons").prop("checked");
USEROPTS.qbtn_idontlikechange = $("#us-oldbtns").prop("checked"); USEROPTS.qbtn_idontlikechange = $("#us-oldbtns").prop("checked");
@ -2697,11 +2695,6 @@ function vimeoSimulator2014(data) {
/* Vimeo Simulator uses the raw file player */ /* Vimeo Simulator uses the raw file player */
data.type = "fi"; data.type = "fi";
/* For browsers that don't support native h264 playback */
if (USEROPTS.no_h264) {
data.forceFlash = true;
}
/* Convert youtube-style quality key to vimeo workaround quality */ /* Convert youtube-style quality key to vimeo workaround quality */
var q = { var q = {
small: "mobile", small: "mobile",