responsive-youtube-player-with-playlist
responsive-youtube-player-with-playlist copied to clipboard
Script firing before YouTube iFrame API is ready
I was having an issue with the vidoes not being loaded and the playlist not being built but with no errors in the console. Finally, I determined that onYouTubeIframeAPIReady was firing before it was finished loading. The script was making it to line 90 (hID.appendChild(tag);) but nothing more. I found this related issue (https://stackoverflow.com/questions/18139277/loading-youtube-api-in-jquery) and when I changed the onYouTubeIframeAPIReady function to the below it began working for me.
// YOUTUBE API CALLBACK
window.onYouTubeIframeAPIReady = function () {
if((typeof YT !== "undefined") && YT && YT.Player){
console.log( 'Youtube API script loaded. Start players.' );
$('[data-rypp]').each(function(idx, el) {
$(el)[0].rypp_data_obj.onYTIframeAPIReadyCallback();
});
} else {
setTimeout(onYouTubeIframeAPIReady, 50);
}
};