From cd22570c405f6d2dcc5dc956e769ed3da0f940af Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sun, 4 Jan 2015 16:46:40 -0500 Subject: [PATCH] Hopefully fix youtube setPlaybackQuality once and for all --- www/js/player.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/www/js/player.js b/www/js/player.js index ae90590a..7431bb59 100644 --- a/www/js/player.js +++ b/www/js/player.js @@ -18,6 +18,7 @@ var YouTubePlayer = function (data) { self.videoId = data.id; self.videoLength = data.seconds; self.theYouTubeDevsNeedToFixThisShit = false; + self.whyDoesSetPlaybackQualityHaveARaceCondition = true; var wmode = USEROPTS.wmode_transparent ? "transparent" : "opaque"; self.player = new YT.Player("ytapiplayer", { videoId: data.id, @@ -34,6 +35,13 @@ var YouTubePlayer = function (data) { PLAYER.setVolume(VOLUME); }, onStateChange: function (ev) { + if (self.whyDoesSetPlaybackQualityHaveARaceCondition) { + self.whyDoesSetPlaybackQualityHaveARaceCondition = false; + + if (USEROPTS.default_quality) { + self.player.setPlaybackQuality(USEROPTS.default_quality); + } + } /** * Race conditions suck. @@ -73,6 +81,12 @@ var YouTubePlayer = function (data) { self.load = function (data) { if(self.player && self.player.loadVideoById) { self.player.loadVideoById(data.id, data.currentTime); + 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); + } self.videoId = data.id; self.videoLength = data.seconds; }