From 033fbbf08aa48c3fcdc9d18f78e236dbfef2dd6b Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 16 Oct 2013 21:50:31 -0500 Subject: [PATCH] Hack around YouTube HTML5 player race condition -- Really guys? --- changelog | 4 ++++ www/assets/js/player.js | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/changelog b/changelog index 810158ed..4fb0e8c5 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +Wed Oct 16 21:48 2013 CDT + * www/assets/js/player.js: Add a stupid timeout hack to address + a race condition in YouTube's HTML5 player. Seriously? + Wed Oct 16 17:34 2013 CDT * lib/utilities.js: Add a "Set" wrapper around objects to represent sets. diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 44d6c437..934f3d06 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -67,8 +67,11 @@ var YouTubePlayer = function (data) { self.load = function (data) { if(self.player && self.player.loadVideoById) { self.player.loadVideoById(data.id, data.currentTime); - if(VIDEOQUALITY) + if(VIDEOQUALITY) { self.player.setPlaybackQuality(VIDEOQUALITY); + // What's that? Another stupid hack for the HTML5 player? + self.player.setPlaybackQuality(VIDEOQUALITY); + } self.videoId = data.id; self.videoLength = data.seconds; } @@ -723,7 +726,6 @@ var ImgurPlayer = function (data) { iframe.attr("height", VHEIGHT); var prto = location.protocol; iframe.attr("src", prto+"//imgur.com/a/"+self.videoId+"/embed"); - console.log(prto); iframe.attr("frameborder", "0"); iframe.attr("scrolling", "no"); iframe.css("border", "none"); @@ -804,8 +806,20 @@ function handleMediaUpdate(data) { } if (wait) { - PLAYER.seek(0); - PLAYER.pause(); + var tm = 1; + /* 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) + */ + if (PLAYER.type === "yt") { + tm = 500; + } + setTimeout(function () { + PLAYER.seek(0); + PLAYER.pause(); + }, tm); return; }