TheWidlarzGroup / react-native-video

A <Video /> component for react-native
https://docs.thewidlarzgroup.com/react-native-video/
MIT License
7.23k stars 2.91k forks source link

[Feature]: Paused state from ref #4226

Closed maksymhcode-care closed 1 month ago

maksymhcode-care commented 1 month ago

Description

Not crucial, but do you think getting play/pause state from ref can be added?

Why it is needed ?

Having ability to get this state locally can help with optimization

Possible implementation

No response

Code sample

No response

github-actions[bot] commented 1 month ago

Thank you for your feature request. We will review it and get back to you if we need more information.

cordovalegacy commented 1 month ago

Yes this would be a great thing to have

freeboub commented 1 month ago

This should be implemented on js side. Register on the event in Video.tsx and save the state to a ref. The accessor just needs to return the value on the ref. (Can also be implemented on the app side, but it can but integrated in the package). Ping @seyedmostafahasani I know you start something similar.

paulrinaldi commented 1 month ago

Yeah this could be implemented as @freeboub suggests. The way the exoplayer lets us keep track of state is by isPlayingChanged events in any class that implements Player.Listener (in rnv, the class ReactExoplayerView does).

I believe you @maksymhcode-care could implement in your video player containing component the following currently though:

const videoIsPlaying = useRef(false);

<Video
  onPlaybackStateStateChanged={(data) => videoIsPlaying.current = data.isPlaying}
  />
maksymhcode-care commented 1 month ago

Yeah this could be implemented as @freeboub suggests. The way the exoplayer lets us keep track of state is by isPlayingChanged events in any class that implements Player.Listener (in rnv, the class ReactExoplayerView does).

I believe you @maksymhcode-care could implement in your video player containing component the following currently though:

const videoIsPlaying = useRef(false);

<Video
  onPlaybackStateStateChanged={(data) => videoIsPlaying.current = data.isPlaying}
  />

Yeah, something like that would works, thanks