I'm trying to make a live stream feature, I have an array of programs (videos), every video has startDate and endDate. If I'm running some video and the current time equals the end time of the video, it should run the main function (that calculates the time and run the new video).
const programs = [
{ video: "URL", startDate: 1644405993, endDate: 1644406032 },
{ video: "URL", startDate: 1644405993, endDate: 1644406032 },
{ video: "URL", startDate: 1644405993, endDate: 1644406032 },
{ video: "URL", startDate: 1644405993, endDate: 1644406032 }
];
Can I add any observer for example to run the function when the current time equals the end time of the current program or I can make it in another way?
The main function that should be run again:
const runningVideo = (newPrograms) => {
const curTime = Math.floor(new Date().getTime() / 1000);
const currentProgram = newPrograms.filter(
p => p.startDate < curTime && p.endDate > curTime
);
setPlayerDetails(currentProgram.length ? currentProgram[0].videoPath : advertisement)
};
**NOTE: ** It's a live stream so every program depends on the start and the end time, I mean the video shouldn't be ended to start the next video, so I can't use onEndedVideo for example.