In HTML5, it is likely that the getCurrentTime () and postMessage functions in the Youtube API are associated with the currentTime property and the timeupdate event of the HTML5 media item specification.
The speed with which the timeupdate event fires varies between browsers and today cannot be adjusted to the level of accuracy you are looking for (Flash is still a bit ahead of this). According to specification :
If the time was reached by the usual monotonous increase in the current playback position during normal playback, and if the user agent has not fired a timeupdate event in the element in the last 15-250 ms and has not yet completed event handlers for such an event, then the user agent must queue the task for fire a simple event called timeupdate in the element. (In other cases, such as explicit requests, the corresponding events are activated as part of the overall process of changing the current playback position.)
An event, therefore, should not fire faster than about 66 Hz or slower than 4 Hz (provided that the event handlers do not take more than 250 ms to fire). It is recommended that user agents change the frequency of the event based on the system load and the average cost of processing the event each time, so user interface updates are not more frequent than the user agent can comfortably process when decoding video.
For the currentTime property, precision is expressed in seconds . Any accuracy below the second is a browser-specific implementation and should not be taken for granted (in reality, you will get secondary accuracy in modern browsers like Chrome, but with variable performance).
In addition, the Youtube API can throttle all of these things to get to a larger common point with an accuracy of 250 ms and make all browsers happy (therefore, 4 events per second and what you noticed in your tests). For your scenario, you should try to scale the animation to this accuracy value of 250 ms and provide some margin of error for better user convenience. In the future, browsers and HTML5 will improve, and I hope we get true millisecond accuracy.
source share