views:

198

answers:

2

Is there an elegant way to pause html 5 video at a specific time?

I tried two ways:

  1. Use the timeupdate event and see if the currentTime property is greater than the desired time and make a call to pause(). This performs well in Firefox, other Browsers sometimes lag behind and render additional frames before the video really pauses.
  2. Use TimedTracks and a Cue with the PauseOnExit Flag set to true. Unfortunatly, no browser implements TimedTracks...

Do you have other ideas?

Cheers, Stefan

+1  A: 

It sounds like you want the video to play up to a certain point and then pause. This isn't possible with the current API. What you can do, however, is to use the timeupdate event to pause just before the desired time and then set currentTime to the desired time. Seeking should work when paused too, so this should pause you at the same frame every time (module browser bugs).

foolip
+2  A: 

You can user the timeupdate event to check the currentTime and once it has gone over your stop time, pause it. The resolution for the timeupdate event may be up to 250ms, which isn't great.

So, alternatively, you can poll the currentTime with setInterval at a higher rate, e.g. every 50ms and pause the video when it gets past your stop time. That's probably more reliable, but creates a higher load on your browser.

A callback interface for the video element is still in development, which will eventually solve this issue.

Silvia