Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get position change events in Javascript for <video> in Mobile Safari?

I want to execute a JavaScript function every second, or whenever the time position changes on a Mobile Safari video player during playback.

Is there an event listener or some way of achieving this? I see how to do it on-demand here:

In Safari for iPad, how can I get the current video position via Javascript?

However, I'm looking for a way to fire the function automatically instead of requiring user interaction to trigger getting the position. Can this be done?

like image 274
Brandon Avatar asked Oct 10 '22 03:10

Brandon


1 Answers

There's a ton of events you can hook into with HTML5 video. Not all will be supported by every browser, but Mobile Safari should do a pretty good job with what you need for this, which is the "timeupdate" event.

video.addEventListener('timeupdate', function() {
  console.log('video time: ' + video.currentTime);
});

You can see a demonstrator for the events here: http://www.w3.org/2010/05/video/mediaevents.html

like image 69
mahemoff Avatar answered Oct 11 '22 15:10

mahemoff