我无法让视频在 2 秒后循环播放。它应该在视频暂停后循环播放。我不确定是否会实现这一点。该功能工作正常,但不循环。
function playVideo() {
var starttime = 0; // start at 0 seconds
var endtime = 2; // stop at 2 seconds
var video = document.getElementById('videoElm');
video.addEventListener("timeupdate", function() {
if (this.currentTime >= endtime) {
this.pause();
// SHOULD LOOP HERE?
}
}, false);
//suppose that video src has been already set properly
video.load();
video.play();
try {
video.currentTime = starttime;
} catch (ex) {
//handle exceptions here
}
}
playVideo();Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<video id="videoElm" autoplay muted controls loop>
<source …Run Code Online (Sandbox Code Playgroud)