Add playbackStalled and Resume events

This commit is contained in:
Stanisław Chmiela 2016-04-28 14:38:21 +02:00
parent b55f71a29d
commit b37243fca2
2 changed files with 19 additions and 0 deletions

View File

@ -38,6 +38,7 @@ static NSString *const playbackRate = @"rate";
BOOL _muted; BOOL _muted;
BOOL _paused; BOOL _paused;
BOOL _repeat; BOOL _repeat;
BOOL _playbackStalled;
NSString * _resizeMode; NSString * _resizeMode;
BOOL _fullscreenPlayerPresented; BOOL _fullscreenPlayerPresented;
UIViewController * _presentingViewController; UIViewController * _presentingViewController;
@ -48,6 +49,7 @@ static NSString *const playbackRate = @"rate";
if ((self = [super init])) { if ((self = [super init])) {
_eventDispatcher = eventDispatcher; _eventDispatcher = eventDispatcher;
_playbackStalled = NO;
_rate = 1.0; _rate = 1.0;
_volume = 1.0; _volume = 1.0;
_resizeMode = @"AVLayerVideoGravityResizeAspectFill"; _resizeMode = @"AVLayerVideoGravityResizeAspectFill";
@ -322,6 +324,11 @@ static NSString *const playbackRate = @"rate";
[_eventDispatcher sendInputEventWithName:@"onPlaybackRateChange" [_eventDispatcher sendInputEventWithName:@"onPlaybackRateChange"
body:@{@"playbackRate": _player.rate, body:@{@"playbackRate": _player.rate,
@"target": self.reactTag}]; @"target": self.reactTag}];
if(_playbackStalled && _player.rate > 0) {
[_eventDispatcher sendInputEventWithName:@"onPlaybackResume"
body:@{@"playbackRate": _player.rate,
@"target": self.reactTag}];
}
} }
} else { } else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
@ -335,6 +342,16 @@ static NSString *const playbackRate = @"rate";
selector:@selector(playerItemDidReachEnd:) selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification name:AVPlayerItemDidPlayToEndTimeNotification
object:[_player currentItem]]; 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 - (void)playerItemDidReachEnd:(NSNotification *)notification

View File

@ -30,6 +30,8 @@ RCT_EXPORT_MODULE();
@"onVideoFullscreenPlayerWillDismiss", @"onVideoFullscreenPlayerWillDismiss",
@"onVideoFullscreenPlayerDidDismiss", @"onVideoFullscreenPlayerDidDismiss",
@"onReadyForDisplay", @"onReadyForDisplay",
@"onPlaybackStalled",
@"onPlaybackResume",
@"onPlaybackRateChange" @"onPlaybackRateChange"
]; ];
} }