PDA

View Full Version : Using HTML 5 to stop a video before complete



Shammus
05-25-2012, 03:38 PM
Working on an iPad app where I'm calling a video with an HTML5 tag as seen below. The video is set to start upon page load. Question is, I want to have the video stop automatically about 90% of the way through the video. Is there a way using HTML 5 or even Javascript to automatically stop a video at a certain point or after a specific percentage of the video has already played?? Thanks in advance....


<video name="vid2" id="vid2" style="width:1024px; height:550px" loop poster="images/postervid.png" autoplay="autoplay">
<source src="videos/testvideo.mp4" preload="auto" />
</video>

jscheuer1
05-28-2012, 08:37 AM
I know that on iPhone, the video will not autoplay. I think iPad is the same, but perhpas not. Have you tested that part out, does it autoplay on iPad?

If so, you can gain a javascript reference to the tag and perhaps monitor its on progress index as a divisor of its total length. When that's less than or equal to 0.1, 90% will have played and you can issue a stop command. All of these are available in the HTML 5 video javascript and HTML api:

https://developer.mozilla.org/en/Using_HTML5_audio_and_video

is a good place to start and there are references at the bottom for further exploration. On that page it suggests using the #t= parameter to set the start and end times. That's a completely HTML solution to your question - that is if you know how long the video is. But it might or might not work on the iPad:

https://developer.mozilla.org/en/Using_HTML5_audio_and_video#Specifying_playback_range

You can also Google:

html5 video javascript api

However, not all aspects of the video tag and its javascript api are supported in all browsers or on all platforms. Generally you can Google that as well if you know what feature you want and what browser/platform combo you want to run it on.

Another approach is to use a plugin like jqplayer:

http://jqplayer.vebersol.net/

or jplayer:

http://jplayer.org/

brainsmith
06-14-2012, 01:07 PM
Yes, it’s possible to stop video at any particular time through java script into HTML 5. For this, you have to include “var” data type as “var endtime = 90”. After this add if condition as “if (this.currentTime >= endtime)” then “this.pause();” This is simple coding for pause video at anytime.

bernie1227
06-14-2012, 10:41 PM
I know that on iPhone, the video will not autoplay. I think iPad is the same, but perhpas not. Have you tested that part out, does it autoplay on iPad?

If it help, I'm on an iPad now and I can check