如何从特定位置启动HTML 5视频?

时间:2014-03-19 06:57:13

标签: javascript html html5 html5-video

<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后从头开始播放视频。我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

<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>