Play video from a playlist according to date and time has how?

Asked

Viewed 50 times

-1

hello i am creating a system webtv/playlist have the following html code :

<html>
<head>
<meta charset="utf-8">
</head>
<body>
<video id="player-video" controls controlsList="nodownload" class="player-video" ></video>
</body>
</html>

and a script like that:

<script type="text/javascript">
    //iniciando o script

(function () {
    var playerVideo = document.getElementById("player-video");
    var current = 0;
    var videos = [];

    videos.push("video_1.mp4");
    videos.push("video_2.mp4");
    videos.push("video_3.mp4");
    videos.push("video_4.mp4");
    videos.push("video_5.mp4");

    function nextVideo() {
        playerVideo.src = videos[current];

        current++;

        playerVideo.play();

        if (current >= videos.length) {
            current = 0;
        }
    }

    playerVideo.addEventListener("ended", nextVideo);

    nextVideo();

})();
</script>

so far nothing else,more what I really want and that depending on the time it plays a specific video example:

when it is 12:00 he plays the video_1.mp4

when it’s 1:00 he plays the video_2.mp4

is that clear? ,?

2 answers

0


Yes. You will need to fetch the local time used in the Date class.

var date = new Date();
if(date.getHours() == 12){
    var video = document.getElementById("video");
    video.src = urls[i++];
    video.play();
}

Example https://jsfiddle.net/c81ozf5s/1/

0

Well, in data logic...

You can use the object Date!

To access the values of the object, you must first insert it into a variable:

var date = new Date();

From there, you have easy access to information from string using native methods, such as .getHours(Which is what interests you at the moment) and insert into another variable.

Applying:

Objeto Date() dentro da variável

(Called at 8 o'clock)

And so, you can draw up a parole or a switch()from that, and modify the video to be displayed from a predefined variable that receives such an HTML element.

Example:

let video = document.querySelector('#video0');


switch (hora){

case 13: video = document.querySelector('#video1') 
}

And basically this is it, you can choose a good event on the page to activate a function to check the time and, if this is it or that, change from your taste.

That was the simplest way I could explain, and the examples are kind of "hard coded", but it was only to demonstrate the principle of the thing, I hope to have helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.