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!开发者_如何学JAVA
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?
This works perfectly for me on an iphone/ipad/safari/chrome
$('#video_1').bind("ended",videoFinished);
function videoFinished(e) { console.log("im done); }
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>
精彩评论