Hello, I am trying to embed my youtube video from my channel. But instead of embedding every time I have a new video I want it to autoplay the latest one. My link is: https://www.thenhans.com/
HTML CODE:
/*
[[x_video_embed][/x_video_embed]]
*/
and here is the JS:
var reqURL = “https://api.rss2json.com/v1/api.json?rss_url=” + encodeURIComponent(“https://www.youtube.com/feeds/videos.xml?channel_id=”);
function loadVideo(iframe){
$.getJSON( reqURL + iframe.getAttribute(‘id’),
function(data) {
var videoNumber = (iframe.getAttribute(‘vnum’)?Number(iframe.getAttribute(‘vnum’)):0);
console.log(videoNumber);
var link = data.items[videoNumber].link;
id = link.substr(link.indexOf("=") + 1);
iframe.setAttribute(“src”,“https://youtube.com/embed/”+id + “?controls=0&autoplay=1&mute=1”);
}
);
}
var iframes = document.getElementsByClassName(‘latestVideoEmbed’);
for (var i = 0, len = iframes.length; i < len; i++){
loadVideo(iframes[i]);
}
Thanks