LonelyCpp / react-native-youtube-iframe

A wrapper of the Youtube-iframe API built for react native.
https://lonelycpp.github.io/react-native-youtube-iframe/
MIT License
598 stars 153 forks source link

emit elapsed time is not correctly #271

Closed HieuNguyen414 closed 1 year ago

HieuNguyen414 commented 1 year ago

https://lonelycpp.github.io/react-native-youtube-iframe/elapsed-time I run app in emulator and tracking elapsed time in setinterval and video emit more than 1s (1,2s), what's wrong ` useEffect(() => {

if (stateVideo === 'playing') {
  const interval = setInterval(() => {
    players.current?.getCurrentTime().then((current: number) => {
      setCurrentTime(current);
    });
  }, 100);
  return () => {
    clearInterval(interval);
  };
}

}, [stateVideo]);

`

screenshot image

LonelyCpp commented 1 year ago

its not clear where you're printing this "run <x>", so not sure what you're actually printing here.

however you should know that set-interval does does not guarantee that your callback will be called exactly after the given time. They tend to drift a little depending on how occupied the main thread is. Here's a stackoverflow discussion about it. You'd have to either increase sampling rate OR decrease accuracy in UI.

This library is only responsible for giving you an elapsed time. Other time-keeping tasks are up to the consumer