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>
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With