-2

I have the following code to display a youtube video as the background of my site

<iframe frameBorder="0" height="100%" width="100%"
src="https://youtube.com/embed/ID?autoplay=1&controls=0&showinfo=0&autohide=1">

How can I make ID be selected from an array of ID's, i'm new to this but think i need to use a javascript script with arrays to select a random one?

Thanks

Solved I used this https://gist.github.com/alishutc/a6b1b0fc11a28a627897

Luke Prior
  • 885
  • 2
  • 11
  • 34
  • Possible duplicate of [Javascript random youtube video autoplay](https://stackoverflow.com/questions/22128689/javascript-random-youtube-video-autoplay) – Durga Feb 21 '18 at 06:38

1 Answers1

0

try using javascript

var id = ['WfmeUdQb4ek', 'CJdOiXwCyzY', '6pilrScSXms', 'TiFthD8t_DI'];

//console.log(id);
setTimeout("changeVideo()", 5000);
var x = 0;

function changeVideo() {
  console.log(id[x]);
  //console.log("https://youtube.com/embed/"+id[x]+"?autoplay=1&controls=0&showinfo=0&autohide=1");
  document.getElementById("video").src = "https://youtube.com/embed/" + id[x] + "?autoplay=1&controls=0&showinfo=0&autohide=1";
  x++;
}
<!--<iframe frameBorder="0" height="100%" width="100%"
src="" id="video"></iframe>-->
<iframe width="560" height="315" src="" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen id="video"></iframe>
Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39