HTML 5视频已结束 [英] HTML 5 video ended

查看:133
本文介绍了HTML 5视频已结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从HTML 5视频标签中收听视频'已结束'事件。它似乎在测试期间非常不明智地被解雇。大多数时候它根本没有发送。我已经使用Adobe Midea编码器将我的.mov编码为mp4。

Im trying to listen to the video 'ended' event from the HTML 5 video tag. It seems to be fired very imtermitently during testing. Most times it doesnt get sent at all. I have encoded my .mov to an mp4 with Adobe Midea Encoder.

是否有人知道它可能无法正常工作,我是否应该在媒体编码器外部编码我的文件更好的结果。

Does anybody know why it might not be working and should I be encoding my files outside on media encoder for better results.

这就是我听到结束偶数的方式(Nel是视频元素;):

This is how im listening to the ended even (Nel is the video element;):

el.addEventListener("ended", this.endHandler);

这是基本的HTML即时消息:

This is the basic HTML im using:

<video id="v1"></video>

我用代码动态设置视频src。它玩得很好,有时我得到结束的事件,但并不总是。

Im setting the video src dynamically with code. It plays fine, sometimes I get the ended event but not always.

谢谢

推荐答案

视频有时会在实际持续时间之前停止播放。类似于0.0000025秒的东西,这意味着结束的事件没有被发送。

It seems a video sometimes stops playing just before the actual duration time. Something like 0.0000025 secs before, which means the ended event isnt sent.

要解决这个问题,请将持续时间四舍五入并检查setInterval上的当前时间。

To fix this im rounding the duration and checking the current time on a setInterval.

//duration = 5.26 ( rounded down from 5.2600041)
if(this.video.currentTime >= this.duration) {
  //VIDEO ENDED
}

这篇关于HTML 5视频已结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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