I found this javascript code on Stack Overflow. I believe it is from a user named “Obsidian Age.” It has worked flawlessly for me, but I was wondering if this code could be modified so that each time a random video ends, it continues to play another random video, like a loop.
In the example, I only show three sample embedded videos, but I plan on adding more videos to the playlist. Thank you very much in advance.
var playlist = [
"https://www.youtube.com/embed/qXYb8R3_B0k",
"https://www.youtube.com/embed/Gi1P6UFTioQ",
"https://www.youtube.com/embed/RDZ0SdlKPXU",
];
var myFrame = document.getElementsByClassName("frame")[0];
function getRandomUrl(myFrame) {
var index = Math.floor(Math.random() * playlist.length);
var url = playlist[index];
myFrame.src = url;
}
function codeAddress() {
getRandomUrl(myFrame);
}
codeAddress();
console.log(myFrame.src);
<iframe class="frame" src="" style="width:640px; height:360px"></iframe>
Aucun commentaire:
Enregistrer un commentaire