Search code examples
javascriptvideoscheduled-tasksmedia-playerautoplay

How to schedule an autoplay video playlist


I generally deal with wordpress, and I'm not a php nor java expert.I'm searching for a script which could automatically autoplay different videos at different times of the day, like a tv channel schedule. Ex. at 9am "movie1.mp4" - at 11am "movie2.mp4" and so on for all the day. Obviously it should be responsive, and work both on Ios and on Android, other than on Windows. I need it both for a wordpress website, but also for another webpage which has not been built in WP. I suppose I could use the same javascript for both, for what I know, but I don't know exactly how to specify the date and time attributes at which autoplay should start. Thanks for any help, I hope you understood


Solution

  • there are a couple possibilities, the one i would go for is that

    you can preload all the videos in JS and change a video element's source.

    changing source on html5 video tag

    to check the time you can use

    var date = new Date();
    var current_hour = date.getHours(); 
    

    combine that with a timeout and a switch/if statement and it should work to your likings.

    i do however advise against autoplay in any form other than users choice.