Viewing Random Video Generator

Random Video Generator



User: Les C. 8 years ago
Is there a way to open a page and how a video play randomly from a list of video files, then have another play immediately after?

Thanks.


LC

Last edit 8 years ago
User: Roddy 8 years ago
You could try something like this...

<section id="randomVideo">
<video preload="none" controls>
<source type="video/mp4" src="http://vjs.zencdn.net/v/oceans.mp4">
</video>
<video preload="none" controls>
<source type="video/mp4" src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4">
</video>
<video preload="none" controls>
<source type="video/mp4" src="http://mediaelementjs.com/media/echo-hereweare.mp4">
</video>
</section>

<script>
(function () {
"use strict";
var videosSection = document.getElementById("randomVideo");
var videosSectionClone = videosSection.cloneNode();
var videos = videosSection.getElementsByTagName("video");
var randomVideo = videos.item(Math.floor(Math.random() * videos.length)).cloneNode(true);
randomVideo.setAttribute("preload", "auto");
videosSectionClone.appendChild(randomVideo);
videosSection.parentNode.replaceChild(videosSectionClone, videosSection);
randomVideo.play();
})();
</script>

You will need to add some styles for th "randomVideo" container.

-------------------------------
Roddy

Website: http://everwebwidgets.com
Contact: http://everwebwidgets.com/ewWidgets-home/contact.html
NOTE: I am an EverWeb user and NOT affiliated with EverWeb! Any opinions expressed in this forum are my own.
User: Les C. 8 years ago
--Roddy

Thanks. I'll give it a try.


L C


Post Reply
You must login or signup to post.