TheWidlarzGroup / react-native-video

A <Video /> component for react-native
http://thewidlarzgroup.github.io/react-native-video/
MIT License
7.14k stars 2.88k forks source link

Merge all event method into one simple method #3521

Open ChristopherGabba opened 7 months ago

ChristopherGabba commented 7 months ago

Description

Currently there are several events that do specific things:

Really all of these methods could be wrapped up into a single method like the react-native-youtube-iframe onChangeState:

Why it is needed ?

Would really simplify my code. Instead I have to have 4 different methods to handle this scenario. Would be great to have one single method that tracks the current status of the player.

Possible implementation

Not sure :(

Code sample

const onChangeState = useCallback((state: VideoState) =>{
   switch(state):
      case "unstarted":
     // ... handle state
      case "buffering":
     // ... handle state
      case "paused":
     // ... handle state
},[])
KrzysztofMoch commented 7 months ago

Sound like good idea! I will add this to roadmap 👍

zoriya commented 3 weeks ago

I'd love if we could get that before the 7.0, deprecate old events and remove them in v7.

onPlaybackStateChanged is triggered when the player buffers BEFORE onBuffer is called. To prevent pausing (and updating controls) when the player buffers, the only solution is to use a setTimeout() and check if the player has buffered.