<video width="320" height="240" controls>
<source src="Video.mp4#t=03,20" type="video/mp4">
Your browser does not support the video tag.
</video>
在我的代码中,视频从 3 分 20 秒开始。我想在html5中设置#t=03,20后从头开始播放视频。我怎样才能做到这一点?
最佳答案
<video id="vid1" width="320" height="240" controls loop>
<source src="Video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
您必须等到浏览器知道视频的持续时间才能查找特定时间。
<script>
window.onload=function(){
document.getElementById('vid1').addEventListener('loadedmetadata', function() {
this.currentTime = 200;
}, false );
};
</script>
或
function restart1()
{ var video1 = document.getElementById("vid1");
video1.currentTime = 0;
}
<video id="vid1" width="320" height="240" onclick="restart1();" controls>
<source src="Videos.mp4#t=03,61" type="video/mp4">
Your browser does not support the video tag.
</video>
关于javascript - 如何从特定位置开始播放 HTML 5 视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22498514/