Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid video.duration does not load until video.play()
    primarykey
    data
    text
    <p>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 <code>video.play()</code>. Right now my code listens for the <code>'loadedmetadata'</code> 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).</p> <p>On Android, <code>'loadedmetadata'</code> 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 <code>video.play()</code> and after one <code>'timeupdate'</code> event, the <code>video.duration</code> 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. </p> <p>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 <code>video.readyState</code> property and see that it is <code>'4'</code> before the video starts playing, but the duration is still not available until after it starts playing, and the first <code>'timeupdate'</code> event. </p> <p>Our current workaround is querying the <code>video.duration</code> value, and only setting up the event callbacks when <code>video.duration !== 6000</code>. 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. </p> <p>Is there anything I can do to make this cleaner, or am I stuck with the hack for now?</p> <p>[1] <a href="https://stackoverflow.com/questions/2221029/problem-retrieving-html5-video-duration">Problem retrieving HTML5 video duration</a></p> <p>[2] <a href="http://www.broken-links.com/2010/07/08/making-html5-video-work-on-android-phones/" rel="nofollow noreferrer">http://www.broken-links.com/2010/07/08/making-html5-video-work-on-android-phones/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload