假设我有一段4分钟的视频,我希望它从第25秒而不是从开头开始播放。
<video autoplay loop id="bgvid">
<source src="back.mp4" type="video/mp4">
</video>
答案 0 :(得分:5)
尝试附加#t=TIME
<video autoplay loop id="bgvid">
<source src="back.mp4#t=25" type="video/mp4">
</video>
W3.org:媒体片段URI - http://www.w3.org/TR/media-frags/
答案 1 :(得分:1)
document.getElementById('bgvid').addEventListener('loadedmetadata', function() {
this.currentTime = 25;
}, false);
答案 2 :(得分:1)
是的Mohit,我之前一直在寻找相同的功能,根据这个question,您可以尝试这段javascript代码,它对我有用; [它也是一种在特定时间停止视频的方法]
function playVideo() {
var starttime = 2; // start at 2 seconds
var endtime = 4; // stop at 4 seconds
var video = document.getElementById('player1');
//handler should be bound first
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
}
}