Javascript ended event when video playback ends on android
I have been trying to create a web page that will redirect the user after he has watched a video (or if he aborted the playback). I've got this working on the iphone but can't really figure out how it works on the android.
On the Iphone i have found two ways of doing this. using t开发者_JS百科he tag to embed the quicktime plugin and then adding a event listener with javascript to listen to the 'qt_ended' event. This does obviously not work on android because there is no quicktime plugin.
The second thing i tried was using the html5 -tag and listening to the 'ended' event, again this worked on the iphone but to my surprise not on android. In this case i got the video playing on the android phone but no redirect occurred after the video had reached the end. So my guess is that the android browser does not fully support the video-tag and that it does not fire the event.
So at this time i don't really know how to proceed. I'm guessing i could do something similar to the quicktime embed solution but using a plugin available on android. But i cant find any information on what plugins is available on the android and if they support some kind of 'ended'-event.
This is supported in Android 2.2, but not 2.1. Android 1.6 didn't even support the Video tag so that goes without saying.
I've spent some time looking into workarounds and haven't found anything.
I am having the same problem with the ended event (Android 2.1) I have found this but no luck so far. https://github.com/bcrescimanno/droidfix
I ended up detecting for Android 2.1 or below and showing a button that the user could activate which then triggered the ended event.
I used PHP as follow for the detection, but you could easily convert it to JavaScript.
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false){
$androidVersion = intval(substr($_SERVER['HTTP_USER_AGENT'], strpos($_SERVER['HTTP_USER_AGENT'], 'Android')+8, 3));
if($androidVersion < 2.2) {
echo 'android 2.1 or less';
}
}
I found out in some Android testing that this behavior is video file dependent. With some file it do not work. With a re-encoded file, it works.
精彩评论