Variable sync accuracy

This commit is contained in:
calzoneman 2013-05-10 16:31:04 -04:00
parent bafce39107
commit dd67179fd4
3 changed files with 11 additions and 5 deletions

View file

@ -9,7 +9,6 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
const SYNC_THRESHOLD = 2;
var LEADER = false;
var PLAYER = false;
var MEDIATYPE = "yt";
@ -62,7 +61,8 @@ var USEROPTS = {
hidevid : parseBool(getOrDefault("cytube_hidevid", false)),
show_timestamps : parseBool(getOrDefault("cytube_show_timestamps", false)),
modhat : parseBool(getOrDefault("cytube_modhat", false)),
blink_title : parseBool(getOrDefault("cytube_blink_title", false))
blink_title : parseBool(getOrDefault("cytube_blink_title", false)),
sync_accuracy : parseFloat(getOrDefault("cytube_sync_accuracy", 2)) || 2
};
applyOpts();
$("#optlink").click(showUserOpts);

View file

@ -817,6 +817,11 @@ function showUserOpts() {
synch.prop("checked", USEROPTS.synch);
addOption("Synch", synchcontainer);
var syncacc = $("<input/>").attr("type", "text")
.attr("placeholder", "Seconds");
syncacc.val(USEROPTS.sync_accuracy);
addOption("Synch Accuracy", syncacc);
var vidcontainer = $("<label/>").addClass("checkbox")
.text("Hide Video");
var hidevid = $("<input/>").attr("type", "checkbox").appendTo(vidcontainer);
@ -854,6 +859,7 @@ function showUserOpts() {
USEROPTS.css = usercss.val();
USEROPTS.layout = layoutselect.val();
USEROPTS.synch = synch.prop("checked");
USEROPTS.sync_accuracy = parseFloat(syncacc.val()) || 2;
USEROPTS.hidevid = hidevid.prop("checked");
USEROPTS.show_timestamps = showts.prop("checked");
USEROPTS.blink_title = blink.prop("checked");

View file

@ -326,12 +326,12 @@ Media.prototype.update = function(data) {
var time = data.currentTime;
var diff = time - seconds || time;
var a = SYNC_THRESHOLD + 1;
var a = USEROPTS.sync_accuracy + 1;
// If 2 updates in a row have lag, compensate for buffering
if(diff >= a && diff <= 6 && this.diff >= a && this.diff <= 6) {
if(diff >= a && diff <= a*3 && this.diff >= a && this.diff <= a*3) {
this.seek(time + diff);
}
else if(diff < -2 || diff >= SYNC_THRESHOLD) {
else if(diff < -USEROPTS.sync_accuracy || diff >= USEROPTS.sync_accuracy) {
if(diff < 0) {
this.seek(time + 0.5);
}