From eb3fc2373a5861e0b430139dcdbaa55e23f45f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Thu, 28 Apr 2016 14:25:45 +0200 Subject: [PATCH] Add readyForDisplay callback --- RCTVideo.m | 19 +++++++++++++------ RCTVideoManager.m | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index a613ded7..69db2336 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -7,6 +7,7 @@ static NSString *const statusKeyPath = @"status"; static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp"; static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; +static NSString *const readyForDisplayKeyPath = @"readyForDisplay"; @implementation RCTVideo { @@ -213,8 +214,7 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; [self addPlayerItemObservers]; [_player pause]; - [_playerLayer removeFromSuperlayer]; - _playerLayer = nil; + [self removePlayerLayer]; [_playerViewController.view removeFromSuperview]; _playerViewController = nil; @@ -504,6 +504,8 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; _playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player]; _playerLayer.frame = self.bounds; _playerLayer.needsDisplayOnBoundsChange = YES; + + [_playerLayer addObserver:self forKeyPath:readyForDisplayKeyPath options:NSKeyValueObservingOptionNew context:nil]; [self.layer addSublayer:_playerLayer]; self.layer.needsDisplayOnBoundsChange = YES; @@ -517,8 +519,7 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; _controls = controls; if( _controls ) { - [_playerLayer removeFromSuperlayer]; - _playerLayer = nil; + [self removePlayerLayer]; [self usePlayerViewController]; } else @@ -530,6 +531,13 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; } } +- (void)removePlayerLayer +{ + [_playerLayer removeFromSuperlayer]; + [_playerLayer removeObserver:self forKeyPath:readyForDisplayKeyPath]; + _playerLayer = nil; +} + #pragma mark - RCTVideoPlayerViewControllerDelegate - (void)videoPlayerViewControllerWillDismiss:(AVPlayerViewController *)playerViewController @@ -615,8 +623,7 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; [_player pause]; _player = nil; - [_playerLayer removeFromSuperlayer]; - _playerLayer = nil; + [self removePlayerLayer]; [_playerViewController.view removeFromSuperview]; _playerViewController = nil; diff --git a/RCTVideoManager.m b/RCTVideoManager.m index b75e379c..e6d93670 100644 --- a/RCTVideoManager.m +++ b/RCTVideoManager.m @@ -28,7 +28,8 @@ RCT_EXPORT_MODULE(); @"onVideoFullscreenPlayerWillPresent", @"onVideoFullscreenPlayerDidPresent", @"onVideoFullscreenPlayerWillDismiss", - @"onVideoFullscreenPlayerDidDismiss" + @"onVideoFullscreenPlayerDidDismiss", + @"onReadyForDisplay" ]; }