views:

531

answers:

3

I have my standard video tag which is playing fine in Chrome;

<video width="x" height="y" src="video.mp4"></video>

The video itself plays fine on the iPhone, however, is there no way to listen for events? Any kind of event? I'd like to use the 'ended' event, but even a 'click' or 'play' would be helpful!

The standard

video.addEventListener('ended', function() {
  alert('this adds nothing');
}, false);

doesn't work at all, and nor can I track a click event (In the same way) on the video tag.

If not, would it be possible to perhaps add a transparent over the top of the video, track a click event to that as normal but then fire the play event for the video so that the video loads in the separate window as normal?

A: 

Here is an example from Safari HTML5 Audio and Video Guide

<!DOCTYPE html>
<html>
  <head>
   <title>Sequential Movies</title>
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
   <script type="text/javascript">
       // listener function changes src
       function myNewSrc() {
          var myVideo = document.getElementsByTagName('video')[0];
          myVideo.src="http://homepage.mac.com/qt4web/sunrisemeditations/myMovie.m4v";
          myVideo.load();
          myVideo.play();
        }

       // function adds listener function to ended event -->

        function myAddListener(){
         var myVideo = document.getElementsByTagName('video')[0];
         myVideo.addEventListener('ended',myNewSrc,false);
        }
   </script>

  </head>

  <body onload="myAddListener()">
      <video controls
        src="http://homepage.mac.com/qt4web/sunrisemeditations/A-chord.m4v"
       >
      </video>
  </body>
</html>
Shaji
That's almost exactly what I've tried - my example is actually injected via JS, but.. academic - and that event does not fire on the iPhone.
Marc Fowler
I can confirm the above code does fire for the iPad... don't know if that will help at all.
Jeff Beck
That is helpful - thanks!So does that mean it won't work at all on the iPhone? Does anyone know? Can anyone think of some kind of workaround? Basically I need to modify the DOM after the video either ends or, I suppose, once the video is playing (Since it opens in a new window).
Marc Fowler
A: 

I can't get the example from Safari HTML5 Audio and Video Guide to work on iPad with an audio tag. It seems that addEventListener('ended',myNewSrc,false) is not fired at all. I'm trying to solve an issue with audio player loop on iPad. After the file is played, it restarts from beginning and I'm afraid it is an iPad bug. The HTML code is correct. Anyone had the same problem? Where can I found a list of supported event listeners on iPad? TIA

MrBrown
I confirm that the loop problem with audio happens also on Safari for OSX and Windows.
MrBrown
A: 

I haven't tested it yet on the iPhone but you can check this project out.

http://www.kaltura.org/project/HTML5_Video_Media_JavaScript_Library

JeremySpouken