【发布时间】:2013-10-22 03:00:34
【问题描述】:
我正在努力解决自动暂停然后再次播放(手动)的问题。视频在 2 秒后暂停,这很好。现在有另一个按钮,点击该按钮,视频应该从暂停的位置开始播放。
这是我的代码(html):
<div class="restart">Restart after pause</div>
<video id="video" width="400" height="400" id="video" src="http://media.w3.org/2010/05/sintel/trailer.mp4" controls autoplay />
jquery:
jQuery(document).ready(function ($) {
$('#video').get(0).play();
setInterval(function () {
if ($('#video').get(0).currentTime >= 2) {
$('#video').get(0).pause();
}
}, 100);
$(".restart").click(function(event){
$('#video').get(0).play();
setInterval(function () {
if ($('#video').get(0).currentTime >= 6) {
$('#video').get(0).pause();
}
}, 100);
});
});
关于当前时间和设定时间,我绝对不是在正确的道路上。请建议。
JSFiddle 是
http://jsfiddle.net/squidraj/KmQxL/10/
提前致谢。
【问题讨论】:
-
如果你不清除你的时间间隔,它会一直暂停,因为 currentTime 将大于或等于 2
-
也,而不是间隔,使用
timeupdate事件 -
好地方......它现在正在工作......非常感谢你。Fiddle 现在更新了。
-
如何在 jquery 中使用 timeupdate 事件。不知道 :(
-
很确定是
$("video")[0].addEventListener('timeupdate', function(event){...});
标签: javascript jquery html video