Skip to content

Commit

Permalink
Only allow the player layer observer to be cleared if it's set (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
cobarx committed Jun 20, 2018
1 parent b3291ca commit 026afab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ios/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @implementation RCTVideo
BOOL _playerItemObserversSet;
BOOL _playerBufferEmpty;
AVPlayerLayer *_playerLayer;
BOOL _playerLayerObserverSet;
AVPlayerViewController *_playerViewController;
NSURL *_videoURL;

Expand Down Expand Up @@ -794,6 +795,7 @@ - (void)usePlayerLayer
// resize mode must be set before layer is added
[self setResizeMode:_resizeMode];
[_playerLayer addObserver:self forKeyPath:readyForDisplayKeyPath options:NSKeyValueObservingOptionNew context:nil];
_playerLayerObserverSet = YES;

[self.layer addSublayer:_playerLayer];
self.layer.needsDisplayOnBoundsChange = YES;
Expand Down Expand Up @@ -832,7 +834,10 @@ - (void)setProgressUpdateInterval:(float)progressUpdateInterval
- (void)removePlayerLayer
{
[_playerLayer removeFromSuperlayer];
[_playerLayer removeObserver:self forKeyPath:readyForDisplayKeyPath];
if (_playerLayerObserverSet) {
[_playerLayer removeObserver:self forKeyPath:readyForDisplayKeyPath];
_playerLayerObserverSet = NO;
}
_playerLayer = nil;
}

Expand Down

0 comments on commit 026afab

Please sign in to comment.