Skip to content

Commit

Permalink
Merge pull request #1075 from react-native-community/bugfix/remove-pl…
Browse files Browse the repository at this point in the history
…ayerlayer-observer

Fix crash when clearing playerLayer observer after already unset
  • Loading branch information
cobarx authored Jun 20, 2018
2 parents b3291ca + 026afab commit 21cfcfd
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 21cfcfd

Please sign in to comment.