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 temporary position changes on the Mobile Safari video player during playback.

Is there an event listener or some way to achieve this? I see how to do this on request:

In Safari for iPad, how can I get the current position of a video using Javascript?

However, I am looking for a way to automatically launch a function, instead of requiring the user to interact in order to call a position. It can be done?

+4
source share
1 answer

There are many events that you can connect to HTML5 video. Not everyone will be supported in every browser, but Mobile Safari should do a pretty good job of what you need for this, which is the "timeupdate" event.

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

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

+3
source

Source: https://habr.com/ru/post/1388690/


All Articles