在我的代码中,视频在准确的时间开始,但没有播放(视频暂停)。下一个视频在精确的时间开始。请查看我的代码:
var videoSources = new Array();
videoSources[0] = 'https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4';
videoSources[1] = 'https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_2mb.mp4';
videoSources[2] = 'https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_5mb.mp4';
var timesToPlayVideos = new Array();
timesToPlayVideos[0] = "16:7";
timesToPlayVideos[1] = "16:9";
timesToPlayVideos[2] = "16:13";
var videoCount = videoSources.length;
function checkIfTimeForVideo() {
var currentDateTimeStamp = new Date(),
currentTimestamp = currentDateTimeStamp.getHours() + ":" + currentDateTimeStamp.getMinutes();
console.log("currenttime", currentTimestamp);
console.log("currenttime", currentDateTimeStamp);
if (timesToPlayVideos.indexOf(currentTimestamp) > -1) {
var arrayIndex = timesToPlayVideos.indexOf(currentTimestamp),
videoSrcToPlay = videoSources[arrayIndex];
console.log("arrayindexvalue", arrayIndex);
var video = document.createElement("VIDEO");
document.body.appendChild(video);
video.setAttribute("src", videoSrcToPlay);
console.log("video src", videoSrcToPlay);
document.getElementById("myVideo").setAttribute("src", videoSrcToPlay);
document.getElementById("myVideo").load();
//console.log("This",videoSrcToPlay,"is playing");
document.getElementById("myVideo").play();
console.log("hello");
}
}
console.log("Program start from here");
window.setInterval(checkIfTimeForVideo, 5000);
给我有关我的代码的任何建议。
谢谢