souporserious / react-media-player

React audio and video player.

Home Page:https://souporserious.github.io/react-media-player/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use Youtube onTimeUpdate for HTML5 player

ebuzzz opened this issue · comments

Currently, the onTimeUpdate for the HTML5 player is based on the ontimeupdate event that is triggered by the browser. The interval for this event is erratic and a best-effort system ('somewhere between 15 and 250ms').

Using the requestAnimationFrame for fetch the current position seems to be a better setup.

I've added pull request #9 that implements the feature, without backwards compatibility...

I've never experienced this so I'm not sure I want to stray away from the native event. If you look at the W3 test media page there seems to be no sign of an erratic onTimeUpdate event https://www.w3.org/2010/05/video/mediaevents.html

Sorry, erratic isn't the correct word. I mean that the update interval is not the same for each browser. The specs says:

Every 15 to 250ms, or whenever the MediaController's media controller position changes, whichever happens least often, the user agent must queue a task to fire a simple event named timeupdate at the MediaController.

This interval is perfectly fine for updating timers, but I am using the library to render a play 'needle '. With the normal onTimeUpdate, this means the needle will jump from position to position, because it's only updated a few times a second. With requestAnimationFrame, this should be something like 60 times a second.