TheWidlarzGroup / react-native-video

A <Video /> component for react-native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature][BUG]: Destroy method for video player

sbrighiu opened this issue · comments

Description

In our app, we use react-native-track-player for audio content and react-native-video for video content. With the latest version, v6.2.0, we also added the notifications controls and removed the react-native-media-controls library from the codebase.

Is it possible to create a destroy method for the video component, similar to what react-native-track-player has?

Why it is needed ?

cross-compatibility with other media libraries

For example, we have the current issue in iOS:

  1. we destroy the audio player
  2. we first use a video component to playback a video,
  3. we unmount the screen (calling .pause() in the useLayoutEffect return function)
  4. we set up and start playback with the audio player
  5. go to the background state
  6. scrub using the notification controls (which show the audio controls and media art)
  7. video content starts playing and overrides the notification controls

Ideally, I think there should be a way to remove all listeners and reset the notification controls. That is one part of the solution. The other would be to be able to somehow trigger the whole deinit() flow manually so that we can avoid the component still existing in memory.

Possible implementation

I'm pretty sure the notification controls reset is fairly easy to expose.

For the destroy() part, I think the React side could be replaced by a simple view, which could help trigger the native deinit flow. I'm not sure it is doable

Code sample

A bit too complex to set up :)

We "fixed" the issue we have with NowPlaying controls by removing the notification controls from iOS via patch package. It is a band-aid for now; with pip active, our users will have to live with it for a few days.

We tried to set notification controls to false + use a state with default false + set state to false after onLoad gets called (like #3890 suggests). Pretty sure there exists a way to fix it like that, but my patience ran out :)