Pause video and clean up when unmounted
See original GitHub issueIf you remove the video from a view, it keeps playing in the background. You can hear the audio playing, and it continues to occupy memory. It’s also evident if you do a JavaScript reload within the app while you’re debugging.
I can implement a quick and dirty fix by adding this to RCTVideo.m
:
- (void)removeFromSuperview
{
[super removeFromSuperview];
[_player pause];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
That stops the video from playing, but I don’t believe it’s really deleted the object, since dealloc
doesn’t run and the memory graph continues to climb. So I’m sure there’s more work to be done here. I’d offer to make a pull request, but I don’t know Objective-C well enough to do it myself.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Pause video and clean up when unmounted · Issue #6 - GitHub
If you remove the video from a view, it keeps playing in the background. You can hear the audio playing, and it continues...
Read more >javascript - How to properly unload/destroy a VIDEO element
2 - Pause and remove children matching 'video', and then empty the parent container: $(container_selector).children().filter("video").each(function(){ this.
Read more >How to work with React the right way to avoid some common ...
I asked Kent about a better approach to avoid setState on component unmount so I could better optimize React's performance. He went above...
Read more >MediaStreamTrack.stop() - Web APIs - MDN Web Docs - Mozilla
In this example, we see a function which stops a streamed video by calling stop() on every track on a given <video> ....
Read more >Synchronizing with Effects - React Docs Beta
Some Effects need to specify how to stop, undo, or clean up whatever they were doing. ... Press Play/Pause multiple times and see...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@brentvatne okay, as far as I can tell, this is broken again. I have controls which let me navigate to the “next” video in a queue, and the old one keeps playing.
It was happening for me because of incorrect
react-native-screens
version, it should bereact-native-screens@^1.0.0-alpha.23
(https://reactnavigation.org/docs/en/getting-started.html#installing-dependencies-into-a-bare-react-native-project)