HTML5视频时间更新事件未触发 [英] HTML5 video timeupdate event not firing

查看:144
本文介绍了HTML5视频时间更新事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有一个< video> 元素:

I do have a <video> element on my page:

<video id="myVideo">
    <source src="vid.mp4" type="video/mp4" />
    <source src="vid.ogg" type="video/ogg" />
</video>

在我的JS中,它显示为:

In my JS it reads:

var v = $('#myVideo')[0];
v.addEventListener('timeupdate',function(){
   alert('I changed');
},false);

现在我将启动我的控制台并输入:

Now I will fire up my console and type:

$('#myVideo')[0].currentTime = 2;

显示的框架将更改,但事件不会触发。根据 timeupdate 的规范应该在 currentTime发生更改时触发,所以我不认为我使用错误的事件?我使用的所有其他事件(即播放& 已结束)正常工作。

The displayed frame will change, yet the event will not fire. According to the specs timeupdate should fire when currentTime was changed, so I do not think I am using the wrong event? All other events I am using (i.e. play & ended) are working just fine.

有很多类似的问题,但所有这些似乎都是过时的错误?这是另一个错误(我在Chrome 17和FF10中进行了测试),还是在事件结构中发生了什么变化?或者我错过了一些完全不同的东西?

There are a lot of similar questions out there, yet all of those seem to be outdated bugs? Is this yet another bug (I tested in Chrome 17 and FF10) or did anything change in the event structure? Or am I missing something completely different?

编辑:
我只是注意到这个问题只会在视频没有还没玩所以当我这样做:

I just noticed that this problem will only occur when the video has not yet played. So when I do:

$('#myVideo')[0].play();
$('#myVideo')[0].pause();
$('#myVideo')[0].currentTime = 2;

事件将会像它一样开始。

The event will fire just like it should.

推荐答案

所以,正如在我的问题编辑中已经说过的,我用一个简单而愚蠢的方法解决了这个问题。只要做:

So, as already stated in the edit to my question I solved this with a simple and rather stupid approach. Just do:

video.play();
video.pause();

以初始化播放头。那么即使没有人启动视频,也应该能够获得 timeupdate 事件。

to "initialize" the playhead. Then one should be able to get timeupdate events even if no one ever started the video.

:奇怪的是,将 preload 设置为 auto 确实触发了视频的预加载,但它似乎没有初始化播放头。

On a side note: strangely, setting preload to auto does trigger a preload of the video, yet it does not seem to initialize the playhead.

这篇关于HTML5视频时间更新事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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