Javascript 播放几秒钟的视频onclick
有没有办法只播放几秒钟的html视频 当前,当用户单击表格行时,视频将搜索到预定义的时间(下面突出显示)。因此,在下面的示例中,视频将搜索到7秒 有没有办法从秒开始播放视频10秒?i、 e搜索到00:07,播放到00:17,然后停止Javascript 播放几秒钟的视频onclick,javascript,jquery,html,video,Javascript,Jquery,Html,Video,有没有办法只播放几秒钟的html视频 当前,当用户单击表格行时,视频将搜索到预定义的时间(下面突出显示)。因此,在下面的示例中,视频将搜索到7秒 有没有办法从秒开始播放视频10秒?i、 e搜索到00:07,播放到00:17,然后停止 谢谢您可以创建一个计时器,这样在“搜索”视频后,它将在10秒内停止视频。 所以在你的内心寻找你想要的功能 var Video = $('Video Element')[0]; // After getting the video element play it.
谢谢您可以创建一个计时器,这样在“搜索”视频后,它将在10秒内停止视频。 所以在你的内心寻找你想要的功能
var Video = $('Video Element')[0];
// After getting the video element play it.
Video.play();
// Now create a timer so in 10 second (1s = 1000 so 10s = 10000 ms) it will pause the video.
setTimeout(function(){
Video.pause();
},10000);
您可以将事件与currentTime
属性一起使用
function playVideo() {
var starttime = 7; // start at 7 seconds
var endtime = 17; // stop at 17 seconds
var video = document.getElementById('yourVideoId');
video.addEventListener("timeupdate", function() {
if (this.currentTime >= endtime) {
this.pause();
}
}, false);
//suppose that video src has been already set properly
video.load();
video.play(); //must call this otherwise can't seek on some browsers, e.g. Firefox 4
try {
video.currentTime = starttime;
} catch (ex) {
//handle exceptions here
}
}
我制作了一个小脚本,这可能会有帮助。 用法:
$(document).ready(function() {
var $v = $('#video');
$v.cuepoints({
17: function() {
$v[0].stop();
}
});
$('button').click(function(){
$v[0].play();
try {$v[0].currentTime = 7;} catch(e) {}
});
});
如果在10秒内未调用该函数,则此操作正常。但当时间到了,时间不会重置回10。"/