Android video.duration直到video.play()才加载 [英] Android video.duration does not load until video.play()

查看:554
本文介绍了Android video.duration直到video.play()才加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html5视频,我试图在播放期间以特定间隔设置回调。该视频开始使用带有 video.play()的javascript播放。现在我的代码侦听'loadedmetadata'事件,然后查询持续时间并设置这些回调。适用于移动游猎,但不适用于Android(2.3.4和2.3.7)。

I have an html5 video which I am trying to set up callbacks at certain intervals during playback. The video starts playing from javascript with video.play(). Right now my code listens for the 'loadedmetadata' event, then queries the duration and sets up those callbacks. Works fine on mobile safari, but not on Android (2.3.4 and 2.3.7).

在Android上,'loadedmetadata'似乎在持续时间实际可用之前发出。为了测试这一点,我在代码中的加载过程的每一步都记录了持续时间,以查看实际可以读取的位置。直到 video.play()并且在一个'timeupdate'事件之后, video.duration无论使用哪种视频,属性为6000。我用mp4文件和3gp文件测试了这个。一旦满足这些条件,就可以获得实际持续时间。

On Android, 'loadedmetadata' seems to be emitted before the duration is actually available. To test this, I logged the duration at every step of the loading process in my code to see where it can actually be read. Until video.play() and after one 'timeupdate' event, the video.duration property is 6000, regardless of the video being used. I tested this with an mp4 file and a 3gp file. Once those conditions are met, the actual duration is available.

我发现这篇帖子有类似的问题[1]。未被接受的最高投票答案是我最初如何设置它,它在iOS上运行良好。接受的答案也不起作用,并表明这是一个webkit问题。我记录了 video.readyState 属性,并在视频开始播放之前看到它是'4',但持续时间在它开始播放之后仍然无法使用,并且第一个'timeupdate'事件。

I found this other post with similar issues [1]. The highest voted answer that wasn't accepted is how I originally set this up, and it works fine on iOS. The accepted answer also does not work, and suggests this is a webkit issue. I log the video.readyState property and see that it is '4' before the video starts playing, but the duration is still not available until after it starts playing, and the first 'timeupdate' event.

我们当前的解决方法是查询 video.duration 值,并仅在<$ c时设置事件回调$ c> video.duration!== 6000 。这非常难看,我想深究它,以免这个黑客回来咬人。这里的讨论[2]似乎表明该问题可能与编码有关。也就是说,没有正确编码,android在加载文件之前不会正确读取元数据,或者可能根本没有读取元数据,而是以另一种方式计算持续时间。

Our current workaround is querying the video.duration value, and only setting up the event callbacks when video.duration !== 6000. This is pretty ugly and I'd like to get to the bottom of it, lest this hack come back to bite. A discussion here [2] seemed to suggest that the issue may be related to encoding. That is, not encoded properly, android doesn't read the metadata correctly until the file is loaded, or perhaps at all and it calculates the duration another way.

我能做些什么来使这个更干净,或者我现在坚持使用黑客?

Is there anything I can do to make this cleaner, or am I stuck with the hack for now?

[1] 检索HTML5视频时长的问题

[2] http://www.broken-links.com/2010/07/08/making-html5-video-work-on-android-phones/

推荐答案

我使用一个调用函数的setTimeout来检查持续时间是否可递归。

Id use a setTimeout which calls a function to check whether the duration is available recursively.

这样功能可以在任何信息可用时显示,等等。持续时间。

This way the function can as soon as any information is available, display etc. the duration.

这篇关于Android video.duration直到video.play()才加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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