在HTML5视频中,如何从长视频播放小剪辑? [英] In HTML5 Video , how to play a small clip from a long video?

查看:189
本文介绍了在HTML5视频中,如何从长视频播放小剪辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从超过10分钟长的长视频文件中显示一个小剪辑。该视频片段将在90秒的时间偏移/搜索时间开始,并且持续时间为45秒。我怎样才能做到这一点 ?

I would like to show a small clip from a long video file that is over 10 minutes long. This segment of video would start at time offset /seek time of 90 seconds and would have a duration of 45 seconds . How can I do that ?

推荐答案

Phillip Brown是对的。你可以通过js控制你的html播放器来解决这个问题。例如在这种情况下,视频会自动启动,并在00:10分钟到00:40分钟播放视频文件

Phillip Brown is right. you can solve this by controlling yout html-player via js. for example in this case, the video would autostart and will play the videofile should 00:10min to 00:40min

<video id="yourVideoplayer" width="640" height="480" preload="auto"> //preload="auto" buffers the video if initialize. you cannot seek a video which isn t buffering already
  <source src="test.mp4" type="video/mp4" />
  <source src="test.ogv" type="video/ogg" /> 
  This browser is not compatible with HTML 5
</video>

<script type="text/javascript">
   window.onload = playVideoTeaserFrom(10,40);   //this event will call the function after page was loaded

   function playVideoTeaserFrom (startTime, endTime) {
       var videoplayer = document.getElementById("yourVideoplayer");  //get your videoplayer

       videoplayer.currentTime = starttime; //not sure if player seeks to seconds or milliseconds
       videoplayer.play();

       //call function to stop player after given intervall
       var stopVideoAfter = (endTime - startTime) * 1000;  //* 1000, because Timer is in ms
       setTimeout(function(){
           videoplayer.stop();
       }, stopVideoAfter);

   }
 </script>

可能会有一些错误,但我想你会明白的一点

there might be some bugs in it, but i guess you ll get the point

这篇关于在HTML5视频中,如何从长视频播放小剪辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆