Can u please explain me this code


#1
var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api?version=3";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

/**
This function creates an

function onYouTubeIframeAPIReady() {
for (var iframeElement = document.getElementsByTagName("iframe"), i = iframeElement.length; i-- :wink: {
if (/youtube.com\/embed/.test(iframeElement[i].src)) {
playerObject = new YT.Player(iframeElement[i], {
events: {
'onReady':onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
}
}

/*
The code get executed when the player get Ready.
*/

function onPlayerReady(event) {
console.log("Inside onPlayerReady == YT API Loaded");
}

/*
The following code tracks the State change of the player.
*/

function onPlayerStateChange(event){

if(event.data === YT.PlayerState.PLAYING) {
  interval = setInterval(youtubeSegmentTrack,1000,event['target']);        // The following code calls the below function when the player is in the "Play" state.
  videoCompleted = false;
}
if(event.data === YT.PlayerState.PAUSED) {
  clearInterval(interval);
}
if(event.data === YT.PlayerState.ENDED) {
  clearInterval(interval);
}

}


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.