Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing html5 video "ended" event on iPad

Sometimes my HTML5 video does not generate an "ended" event on the iPad. Seems only to happen when I omit the "controls" attribute and start playback from javascript. It usually works fine the first time, but the second time the video plays out but does not generate an "ended" event. I do call "load()" after each playback in order to reset to the beginning of the clip (because seeking doesn't seem to work at all - see this thread). I have a workaround, which is to track "timeupdate" events and perform my end-of-play actions when vid.currentTime>=vid.duration, but I was wondering if anyone else had experienced this problem. Some relevant code follows.

Cheers -Chris

The document onload function:

function load() {
    var vid = document.getElementById('vid');
    vid.addEventListener('ended', function() {
        alert('video ended');
        vid.load();
    },false);
}

The html:

<body onload="load();">
<h1>HTML5 Video Test</h1>
<input type="submit" value="Play" onclick="document.getElementById('vid').play();">
<video id="vid" src="test.mov" width="640" height="480"></video>
</body>
like image 697
wodenx Avatar asked Oct 06 '10 15:10

wodenx


1 Answers

Don't use load() to force the seek. If you set video.currentTime to 0.1 instead of 0 the video will jump to the beginning and the ended event will still dispatch properly. (Tested on iOS 3.2 and 4.2)

like image 165
Miller Medeiros Avatar answered Sep 26 '22 22:09

Miller Medeiros