From ee788b0c30372a9158cd66af70b4814723439ca1 Mon Sep 17 00:00:00 2001 From: Matt Mascarenhas Date: Wed, 1 Sep 2021 16:38:23 +0100 Subject: [PATCH] cinera_player_pre.js: Fix YouTube initialisation Initialise the player if the YouTube API loads before us --- cinera/cinera.c | 2 +- cinera/cinera_player_pre.js | 33 ++++++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/cinera/cinera.c b/cinera/cinera.c index 30c3787..81f03d6 100644 --- a/cinera/cinera.c +++ b/cinera/cinera.c @@ -23,7 +23,7 @@ typedef struct version CINERA_APP_VERSION = { .Major = 0, .Minor = 10, - .Patch = 0 + .Patch = 1 }; #include // NOTE(matt): varargs diff --git a/cinera/cinera_player_pre.js b/cinera/cinera_player_pre.js index f927d03..ca66876 100644 --- a/cinera/cinera_player_pre.js +++ b/cinera/cinera_player_pre.js @@ -634,19 +634,26 @@ Player.initializePlatform = function(platform_id, callback) { } break; case vod_platform.YOUTUBE: { - if (window.APYoutubeAPIReady === undefined) { - window.APYoutubeAPIReady = false; - window.APCallbacks = (callback ? [callback] : []); - window.onYouTubeIframeAPIReady = function() { - window.APYoutubeAPIReady = true; - for (var i = 0; i < APCallbacks.length; ++i) { - APCallbacks[i](); - } - }; - } else if (window.APYoutubeAPIReady === false) { - window.APCallbacks.push(callback); - } else if (window.APYoutubeAPIReady === true) { - callback(); + if(window.YT && window.YT.loaded) + { + callback() + } + else + { + if (window.APYoutubeAPIReady === undefined) { + window.APYoutubeAPIReady = false; + window.APCallbacks = (callback ? [callback] : []); + window.onYouTubeIframeAPIReady = function() { + window.APYoutubeAPIReady = true; + for (var i = 0; i < APCallbacks.length; ++i) { + APCallbacks[i](); + } + }; + } else if (window.APYoutubeAPIReady === false) { + window.APCallbacks.push(callback); + } else if (window.APYoutubeAPIReady === true) { + callback(); + } } } break; }