时间范围内的HTML5视频 [英] HTML5 video within time frame
问题描述
所以我正在开发一个交互式HTML5视频播放器,目前使用popcorn.js时一切正常,但我现在正试着回去让我的播放器工作而不依赖于popcorn.js。
So I am working on an interactive HTML5 video player, and currently have everything working while using popcorn.js, but I am now trying to go back and make my player work without being dependent on popcorn.js.
使用popcorn.js时,您可以使用以下代码:
When working with popcorn.js, you can use code like:
popcorn.code((
start: 0,
end: 5,
onStart: function( options ) {
//put code here
}
}}
当您的视频时间从0到5时,您的代码将被执行。现在,我我试图在视频的某个时间范围内执行某些代码块,但我似乎无法让它正常工作,只是想知道是否有人可以看到我的错误。
and your code will be executed when the time of your video spans from 0 through 5. Now, I am trying to have certain blocks of code executed within a certain timeframe of the video, but i can't seem to get it working right and was just wondering if someone can see where i am going about this wrong.
while (myVideo.currentTime >= 0 && myVideo.currentTime <= 5)
{
console.log(myVideo.currentTime);
}
这个while循环是al所以运行速度太快,导致浏览器减速并冻结。
但是,如果我尝试使用if循环而不是while循环,它(显然)只检查一次。
This while loop is also running so fast that it causes the browser to slow down and freeze. However, if i try using an if loop instead of a while loop, it (obviously) only checks it once.
推荐答案
你可以检查少于而
循环。
var check = setInterval(function() {
if (myVideo.currentTime >= 5) {
clearInterval(check);
console.log("5 seconds reached");
}
}, 500);
当用户暂停并重新开始或者他跳到另一个时间时,你可以再次开始这个时间表。
You than can start this again when the user pauses and starts over or if he jumps to another time within the timeline.
这篇关于时间范围内的HTML5视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!