我的设计中有一个视频文件,长度为 2 分钟。第一次,视频将从头开始播放,然后视频必须从 1.00 秒循环播放到 2.00 秒。使用 jquery 可以做到这一点吗?我尝试过替代方法。它有效,但视频中有跳跃。 Change video source after the first video ends 。
这是我的代码:
JQuery:
document.getElementById('bgvid').addEventListener('ended', myHandler, false);
function myHandler(e) {
//*what to do?*//
}
HTML:
div class="anim-logo ">
<video playsinline autoplay muted poster="assets/img/video3.jpg" id="bgvid">
<source src="assets/img/video3.webm" type="video/webm">
<source src="assets/img/video3.mp4" type="video/mp4">
</video>
</div><!--end of anim logo-->
最佳答案
你可以这样做:
var video = document.getElementById('videoElm')
video.addEventListener('ended',function(){
// set the video's start position to the video's duration minus 10 seconds. "video.currentTime" is in milliseconds, "video.duration" is in seconds
video.currentTime = (parseInt(video.duration) - 10) * 1000;
video.play();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<video id="videoElm" autoplay muted>
<source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/webm">
</video>
</div>
关于javascript - 从选定的持续时间循环播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39747511/