【发布时间】:2012-04-08 09:19:49
【问题描述】:
我想从一个超过 10 分钟的长视频文件中显示一个小片段。这段视频将从 90 秒的时间偏移/搜索时间开始,持续时间为 45 秒。我怎样才能做到这一点 ?
【问题讨论】:
-
请注意,通过这种方式,您会将整个视频(就文件大小而言可能相当大)传输到客户的设备上。一种用户友好的方法可能已经在编辑中解决了这个问题,并提供一个仅涵盖 sn-p 的特定文件。
标签: html html5-video
我想从一个超过 10 分钟的长视频文件中显示一个小片段。这段视频将从 90 秒的时间偏移/搜索时间开始,持续时间为 45 秒。我怎样才能做到这一点 ?
【问题讨论】:
标签: html html5-video
HTML5 视频还支持Media Fragment URI 规范。这将允许您仅指定要播放的视频片段。使用它相当简单:
<source src="video.mp4#t=30,45" type="video/mp4"/>
将在 30 秒标记处开始视频并在 45 秒标记处暂停视频。
【讨论】:
菲利普布朗是对的。你可以通过js控制你的html-player来解决这个问题。例如,在这种情况下,视频将自动启动并在 00:10 到 00:40 之间播放视频文件
<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>
其中可能有一些错误,但我想你会明白的
【讨论】:
window.onload 设置为未定义,以及代码的其他问题。有明显的错误。
timeupdate 事件,如果vid.currentTime 不在开始到结束之间,则暂停视频