question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pause video and clean up when unmounted

See original GitHub issue

If 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:closed
  • Created 8 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kshahkshahcommented, Sep 21, 2017

@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.

0reactions
CyxouDcommented, Nov 26, 2019
react-native: "0.61"
react-navigation: "4.0.10"

It was happening for me because of incorrect react-native-screens version, it should be react-native-screens@^1.0.0-alpha.23 (https://reactnavigation.org/docs/en/getting-started.html#installing-dependencies-into-a-bare-react-native-project)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found