[英]Detect seeking video event HMTL5 (mainly on iOs4)
I need to detect seeking
event, because on iOs4 there's seeked
but no seeking event.我需要检测
seeking
事件,因为iOS4的还有的seeked
但没有寻求事件。 I would not like to detect the device but the functionality.我不想检测设备,而是检测功能。
I could make an awful addEvent
/ fireEvent
, but I'm looking for something as sexy as 'seeking' in myElement
.我可以做一个糟糕的
addEvent
/ fireEvent
,但我正在寻找像'seeking' in myElement
一样性感的东西。
Any solution?有什么解决办法吗?
var lastUnixTimeStamp;
var lastCurrentVideoTime;
videoplayer.addEvent('timeupdate',function(){
if( !lastUnixTimeStamp && !lastCurrentVideoTime ){ //not defined at first timeupdate event
lastUnixTimeStamp = new Date().getTime();
lastCurrentVideoTime = videoplayer.currentTime;
return;
}
var videoTimeOffset = videoplayer.currentTime - lastCurrentVideoTime; //how many milliseconds was video running
var realTimeOffset = new Date().getTime() - lastUnixTimeStamp; //how many milliseconds were real time running
//guess the numbers are not accurate, so if the difference between both is f.e. < 100ms, video runs normally
if( (videoTimeOffset - realTimeOffset) > 100 ){
//do your seeking magic
}
lastUnixTimeStamp = new Date().getTime();
lastCurrentVideoTime = videoplayer.currentTime;
})
as mentioned in the comment above, might be not the best solutions but should do it.正如上面评论中提到的,可能不是最好的解决方案,但应该这样做。 good luck
祝你好运
This solution will only work if you are seeking forward.此解决方案仅在您向前寻求时才有效。 If you want it to work in seeking backward to, you have to verify if the videoTimeOffset is negative :
如果您希望它向后搜索,则必须验证 videoTimeOffset 是否为负:
var lastUnixTimeStamp;
var lastCurrentVideoTime;
videoplayer.addEvent('timeupdate',function(){
if( !lastUnixTimeStamp && !lastCurrentVideoTime ){ //not defined at first timeupdate event
lastUnixTimeStamp = new Date().getTime();
lastCurrentVideoTime = videoplayer.currentTime;
return;
}
var videoTimeOffset = videoplayer.currentTime - lastCurrentVideoTime; //how many milliseconds was video running
var realTimeOffset = new Date().getTime() - lastUnixTimeStamp; //how many milliseconds were real time running
//guess the numbers are not accurate, so if the difference between both is f.e. < 100ms, video runs normally
if( (videoTimeOffset - realTimeOffset) > 100 || (videoTimeOffset < 0 )){
//do your seeking magic
}
lastUnixTimeStamp = new Date().getTime();
lastCurrentVideoTime = videoplayer.currentTime;
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.