0

I want to play a random video on my website. But I don't know how I can make that, because I'm a noob with HTML & JSS. I searched for a simple way to do that, but I can't find a solution.

Thats my code on the Website, where the different videos should come. Sadly, this doesn't work. He tries to find a file named "video/trailer1.mp4, video/trailer2.mp4"

<section data-video-path="video/trailer1.mp4, video/trailer2.mp4"></section>

Is it possible to add a filename to "trailer1" with a comma or something? Is there an easy way to add a video and it get picked randomly which one is played?

I found a function, that maybe helps to implement random videos. Can i maybe implement the random video thing with the { and } ?

data-plugin-options="{'posterType': 'jpg', 'position': '50% 50%'}"
Razzer
  • 492
  • 1
  • 4
  • 29

2 Answers2

2

You can use a <video> element to play video in the HTML

See this and this

<video class="my-video" controls muted loop autoplay></video>

If you want to change the video source to be a random one then in JavaScrpit:

const possibleVideos = ["video/trailer1.mp4", "video/trailer2.mp4"];
const randomVideo = possibleVideos[Math.floor(Math.random() * possibleVideos.length)];

document.querySelector('video.my-video').src = randomVideo;

ref: link

Huw
  • 289
  • 2
  • 4
0

If you want a video from YouTube It Is The Simple Way

<iframe width="420" height="315"
src="https://www.youtube.com/embed/oHg5SJYRHA0">
</iframe>