javascript - 如何从特定位置开始播放 HTML 5 视频?

标签 javascript html 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后从头开始播放视频。我怎样才能做到这一点?

最佳答案

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

相关文章:

javascript - 如何消除按位循环并将字节作为一个整体处理?

javascript - Notepad++ 批量重写突出显示的数字

javascript - 使用 Javascript 添加几行 HTML 到页面

javascript - 无法访问网络摄像头(Javascript)?

javascript - 嵌套的 WHILE 循环未按预期运行 - Javascript/Google Apps 脚本

html - 向右浮动固定的 div 并旋转它

javascript - 向网页添加分享按钮

javascript - 使用 video-js 跳转到 HTML5 嵌入式视频中的时间戳

jquery - Html5视频剪辑反向

javascript - React Native 渲染组件列表