From b37243fca250bb7ccc257508a1404264a0bb33f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Thu, 28 Apr 2016 14:38:21 +0200 Subject: [PATCH] Add playbackStalled and Resume events --- RCTVideo.m | 17 +++++++++++++++++ RCTVideoManager.m | 2 ++ 2 files changed, 19 insertions(+) diff --git a/RCTVideo.m b/RCTVideo.m index 446eef04..b1144025 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -38,6 +38,7 @@ static NSString *const playbackRate = @"rate"; BOOL _muted; BOOL _paused; BOOL _repeat; + BOOL _playbackStalled; NSString * _resizeMode; BOOL _fullscreenPlayerPresented; UIViewController * _presentingViewController; @@ -48,6 +49,7 @@ static NSString *const playbackRate = @"rate"; if ((self = [super init])) { _eventDispatcher = eventDispatcher; + _playbackStalled = NO; _rate = 1.0; _volume = 1.0; _resizeMode = @"AVLayerVideoGravityResizeAspectFill"; @@ -322,6 +324,11 @@ static NSString *const playbackRate = @"rate"; [_eventDispatcher sendInputEventWithName:@"onPlaybackRateChange" body:@{@"playbackRate": _player.rate, @"target": self.reactTag}]; + if(_playbackStalled && _player.rate > 0) { + [_eventDispatcher sendInputEventWithName:@"onPlaybackResume" + body:@{@"playbackRate": _player.rate, + @"target": self.reactTag}]; + } } } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; @@ -335,6 +342,16 @@ static NSString *const playbackRate = @"rate"; selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:[_player currentItem]]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(playbackStalled:) + name:AVPlayerItemPlaybackStalledNotification + object:nil]; +} + +- (void)playbackStalled:(NSNotification *)notification +{ + [_eventDispatcher sendInputEventWithName:@"onPlaybackStalled" body:@{@"target": self.reactTag}]; + _playbackStalled = YES; } - (void)playerItemDidReachEnd:(NSNotification *)notification diff --git a/RCTVideoManager.m b/RCTVideoManager.m index 2e69ea0c..1eb56369 100644 --- a/RCTVideoManager.m +++ b/RCTVideoManager.m @@ -30,6 +30,8 @@ RCT_EXPORT_MODULE(); @"onVideoFullscreenPlayerWillDismiss", @"onVideoFullscreenPlayerDidDismiss", @"onReadyForDisplay", + @"onPlaybackStalled", + @"onPlaybackResume", @"onPlaybackRateChange" ]; }