Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Player sometimes keeps seeking after view is unmounted #113

Closed
rclai opened this issue Dec 10, 2015 · 13 comments
Closed

[iOS] Player sometimes keeps seeking after view is unmounted #113

rclai opened this issue Dec 10, 2015 · 13 comments

Comments

@rclai
Copy link

rclai commented Dec 10, 2015

This happens on remote video URLs.

Reproduction:

  1. Create Video player with remote video URL (https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4)
  2. Make it play (at this point you'll notice an activity indicator show up at the top left in your status bar, which indicates that it is buffering the video)
  3. Unmount the Video player by either navigating away or change a state variable that causes the player to not show
  4. The activity indicator at the top left in the status bar will keep spinning (it should disappear)

I think this happens when the network request hasn't finished responding and therefore the AVPlayerItem is stuck in seeking mode. I think that in the removeFromSuperview lifecycle, we need to call cancelPendingSeeks on the AVPlayerItem.

@rclai rclai changed the title Player sometimes keeps seeking after View view is unmounted [iOS] Player sometimes keeps seeking after View view is unmounted Dec 10, 2015
@rclai rclai changed the title [iOS] Player sometimes keeps seeking after View view is unmounted [iOS] Player sometimes keeps seeking after view is unmounted Dec 10, 2015
@rclai
Copy link
Author

rclai commented Dec 10, 2015

As a matter of fact, I noticed that the AVPlayerLayer and AVPlayer are cleaned up, but not the AVPlayerItem, so I'm thinking we need to do:

https://github.com/brentvatne/react-native-video/blob/3aa46875a58b857861377dc1528088ae027627e2/RCTVideo.m#L399-L405

[_playerItem cancelPendingSeeks];
[self removePlayerItemObservers]; // This line is already there
_playerItem = nil;

@kitolog
Copy link

kitolog commented Dec 19, 2015

+1 I got this bug too with remote urls

@andresn
Copy link

andresn commented Apr 3, 2016

+1 I'm seeing this when transitioning to different pages via router. @brentvatne your thoughts?

@kitolog
Copy link

kitolog commented Apr 3, 2016

@andresn you can check video component unmount event and pause player. Works for me

@kshahkshah
Copy link

Yes, but is this going to blow up memory by pausing w/o unmounting. This seems like a serious issue if so.

@marlti7
Copy link

marlti7 commented Aug 22, 2018

face the same problem

@yemi
Copy link

yemi commented Apr 18, 2019

Im having problems with videos not unmounting correctly, or at least they seem to trigger the "cannot load more than 16 videos simultaneously even though only 1 video is mounted at a time.

Has anyone found a solution to the unmounting issue?

@pribeh
Copy link

pribeh commented Apr 24, 2019

Experiencing the same here. I'm not quite sure yet what isn't unmounting but there is a memory leak for sure after a video is played.

@maxschmeling
Copy link

maxschmeling commented Apr 26, 2019

I believe I've figured this out for my code, but I have a custom build of react-native-video that always uses AVPlayerViewController so that I can toggle the controls prop without a flicker (I plan to contribute a more general fix for that issue at some point, but haven't had time).

In setSrc, right after [self removePlayerItemObservers] I added:

if (_playerViewController != nil) {
  _playerViewController.player = nil;
}

For me, on an iPhone X running iOS 12.2, I could switch back and forth between two different videos to where setSrc was called 32 times without issue. The 33rd time would break. On an iPhone X running iOS 11.4.1, switching to where setSrc was called 16 times worked, but the 17th time would break.

With the addition of the lines above, I no longer have any issues switching between videos no matter how many times.

I would imagine in the main react-native-video code, a check could be done for both _playerViewController and _playerLayer to clear whichever one is being used.

@sebqq
Copy link

sebqq commented Jul 2, 2019

I'm encountering the same problem. The memory consumption is larger with every video which is played :(

@CHaNGeTe
Copy link
Contributor

CHaNGeTe commented Jul 2, 2019

@jenshandersson
Copy link
Contributor

No that PR didn't fix this, looks like we only handle AVPlayerLayer in dealloc... I will submit a PR.

@CHaNGeTe
Copy link
Contributor

CHaNGeTe commented Jul 9, 2019

Check on 4.4.3

@CHaNGeTe CHaNGeTe closed this as completed Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests