我有一个使用 TimeJump.js 的简单 HTML5 视频播放器(http://davatron5000.github.io/TimeJump/)以允许直接跳转到特定时间代码。
IE。跳转到视频的第 25 分钟。
我想添加对视频播放时长的限制。因此,用户一次只能观看 60 秒的视频。我无法使用媒体 URL 规范(即 #t=25,85),因为视频的开头将根据用户输入的 URL 字符串而更改(使用 TimeJump.js 跳转到视频中的点)
关于如何限制视频播放时长有什么想法吗?
thanks.
我从未使用过 TimeJump.js 但你可以听一下timeupdate媒体元素(音频和视频)的事件。
var video = document.querySelector('video');
video.addEventListener('timeupdate', function() {
// don't have set the startTime yet? set it to our currentTime
if (!this._startTime) this._startTime = this.currentTime;
var playedTime = this.currentTime - this._startTime;
if (playedTime >= 10) this.pause();
});
video.addEventListener('seeking', function() {
// reset the timeStart
this._startTime = undefined;
});
<video controls="true" height="200" width="300">
<source type="video/ogg" src="http://media.w3.org/2010/05/bunny/movie.ogv">
<source type="video/mp4" src="http://media.w3.org/2010/05/bunny/movie.mp4">
</video>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)