Protect events (#444)
This commit is contained in:
parent
9a936c9e8f
commit
2b709a5d54
@ -184,7 +184,7 @@ static NSString *const playbackRate = @"rate";
|
|||||||
CMTime currentTime = _player.currentTime;
|
CMTime currentTime = _player.currentTime;
|
||||||
const Float64 duration = CMTimeGetSeconds(playerDuration);
|
const Float64 duration = CMTimeGetSeconds(playerDuration);
|
||||||
const Float64 currentTimeSecs = CMTimeGetSeconds(currentTime);
|
const Float64 currentTimeSecs = CMTimeGetSeconds(currentTime);
|
||||||
if( currentTimeSecs >= 0) {
|
if( currentTimeSecs >= 0 && self.onVideoProgress) {
|
||||||
self.onVideoProgress(@{
|
self.onVideoProgress(@{
|
||||||
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(currentTime)],
|
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(currentTime)],
|
||||||
@"playableDuration": [self calculatePlayableDuration],
|
@"playableDuration": [self calculatePlayableDuration],
|
||||||
@ -277,12 +277,15 @@ static NSString *const playbackRate = @"rate";
|
|||||||
|
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||||
//Perform on next run loop, otherwise onVideoLoadStart is nil
|
//Perform on next run loop, otherwise onVideoLoadStart is nil
|
||||||
self.onVideoLoadStart(@{@"src": @{
|
if(self.onVideoLoadStart) {
|
||||||
@"uri": [source objectForKey:@"uri"],
|
self.onVideoLoadStart(@{@"src": @{
|
||||||
@"type": [source objectForKey:@"type"],
|
@"uri": [source objectForKey:@"uri"],
|
||||||
@"isNetwork": [NSNumber numberWithBool:(bool)[source objectForKey:@"isNetwork"]]},
|
@"type": [source objectForKey:@"type"],
|
||||||
@"target": self.reactTag
|
@"isNetwork": [NSNumber numberWithBool:(bool)[source objectForKey:@"isNetwork"]]},
|
||||||
});
|
@"target": self.reactTag
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,24 +345,27 @@ static NSString *const playbackRate = @"rate";
|
|||||||
orientation = @"portrait";
|
orientation = @"portrait";
|
||||||
}
|
}
|
||||||
|
|
||||||
self.onVideoLoad(@{@"duration": [NSNumber numberWithFloat:duration],
|
if(self.onVideoLoad) {
|
||||||
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)],
|
self.onVideoLoad(@{@"duration": [NSNumber numberWithFloat:duration],
|
||||||
@"canPlayReverse": [NSNumber numberWithBool:_playerItem.canPlayReverse],
|
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)],
|
||||||
@"canPlayFastForward": [NSNumber numberWithBool:_playerItem.canPlayFastForward],
|
@"canPlayReverse": [NSNumber numberWithBool:_playerItem.canPlayReverse],
|
||||||
@"canPlaySlowForward": [NSNumber numberWithBool:_playerItem.canPlaySlowForward],
|
@"canPlayFastForward": [NSNumber numberWithBool:_playerItem.canPlayFastForward],
|
||||||
@"canPlaySlowReverse": [NSNumber numberWithBool:_playerItem.canPlaySlowReverse],
|
@"canPlaySlowForward": [NSNumber numberWithBool:_playerItem.canPlaySlowForward],
|
||||||
@"canStepBackward": [NSNumber numberWithBool:_playerItem.canStepBackward],
|
@"canPlaySlowReverse": [NSNumber numberWithBool:_playerItem.canPlaySlowReverse],
|
||||||
@"canStepForward": [NSNumber numberWithBool:_playerItem.canStepForward],
|
@"canStepBackward": [NSNumber numberWithBool:_playerItem.canStepBackward],
|
||||||
@"naturalSize": @{
|
@"canStepForward": [NSNumber numberWithBool:_playerItem.canStepForward],
|
||||||
@"width": width,
|
@"naturalSize": @{
|
||||||
@"height": height,
|
@"width": width,
|
||||||
@"orientation": orientation
|
@"height": height,
|
||||||
},
|
@"orientation": orientation
|
||||||
@"target": self.reactTag});
|
},
|
||||||
|
@"target": self.reactTag});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[self attachListeners];
|
[self attachListeners];
|
||||||
[self applyModifiers];
|
[self applyModifiers];
|
||||||
} else if(_playerItem.status == AVPlayerItemStatusFailed) {
|
} else if(_playerItem.status == AVPlayerItemStatusFailed && self.onVideoError) {
|
||||||
self.onVideoError(@{@"error": @{@"code": [NSNumber numberWithInteger: _playerItem.error.code],
|
self.onVideoError(@{@"error": @{@"code": [NSNumber numberWithInteger: _playerItem.error.code],
|
||||||
@"domain": _playerItem.error.domain},
|
@"domain": _playerItem.error.domain},
|
||||||
@"target": self.reactTag});
|
@"target": self.reactTag});
|
||||||
@ -377,17 +383,21 @@ static NSString *const playbackRate = @"rate";
|
|||||||
}
|
}
|
||||||
} else if (object == _playerLayer) {
|
} else if (object == _playerLayer) {
|
||||||
if([keyPath isEqualToString:readyForDisplayKeyPath] && [change objectForKey:NSKeyValueChangeNewKey]) {
|
if([keyPath isEqualToString:readyForDisplayKeyPath] && [change objectForKey:NSKeyValueChangeNewKey]) {
|
||||||
if([change objectForKey:NSKeyValueChangeNewKey]) {
|
if([change objectForKey:NSKeyValueChangeNewKey] && self.onReadyForDisplay) {
|
||||||
self.onReadyForDisplay(@{@"target": self.reactTag});
|
self.onReadyForDisplay(@{@"target": self.reactTag});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (object == _player) {
|
} else if (object == _player) {
|
||||||
if([keyPath isEqualToString:playbackRate]) {
|
if([keyPath isEqualToString:playbackRate]) {
|
||||||
self.onPlaybackRateChange(@{@"playbackRate": [NSNumber numberWithFloat:_player.rate],
|
if(self.onPlaybackRateChange) {
|
||||||
@"target": self.reactTag});
|
self.onPlaybackRateChange(@{@"playbackRate": [NSNumber numberWithFloat:_player.rate],
|
||||||
|
@"target": self.reactTag});
|
||||||
|
}
|
||||||
if(_playbackStalled && _player.rate > 0) {
|
if(_playbackStalled && _player.rate > 0) {
|
||||||
self.onPlaybackResume(@{@"playbackRate": [NSNumber numberWithFloat:_player.rate],
|
if(self.onPlaybackResume) {
|
||||||
@"target": self.reactTag});
|
self.onPlaybackResume(@{@"playbackRate": [NSNumber numberWithFloat:_player.rate],
|
||||||
|
@"target": self.reactTag});
|
||||||
|
}
|
||||||
_playbackStalled = NO;
|
_playbackStalled = NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -411,13 +421,17 @@ static NSString *const playbackRate = @"rate";
|
|||||||
|
|
||||||
- (void)playbackStalled:(NSNotification *)notification
|
- (void)playbackStalled:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
self.onPlaybackStalled(@{@"target": self.reactTag});
|
if(self.onPlaybackStalled) {
|
||||||
|
self.onPlaybackStalled(@{@"target": self.reactTag});
|
||||||
|
}
|
||||||
_playbackStalled = YES;
|
_playbackStalled = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playerItemDidReachEnd:(NSNotification *)notification
|
- (void)playerItemDidReachEnd:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
self.onVideoEnd(@{@"target": self.reactTag});
|
if(self.onVideoEnd) {
|
||||||
|
self.onVideoEnd(@{@"target": self.reactTag});
|
||||||
|
}
|
||||||
|
|
||||||
if (_repeat) {
|
if (_repeat) {
|
||||||
AVPlayerItem *item = [notification object];
|
AVPlayerItem *item = [notification object];
|
||||||
@ -489,9 +503,11 @@ static NSString *const playbackRate = @"rate";
|
|||||||
|
|
||||||
if (CMTimeCompare(current, cmSeekTime) != 0) {
|
if (CMTimeCompare(current, cmSeekTime) != 0) {
|
||||||
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
|
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
|
||||||
self.onVideoSeek(@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
|
if(self.onVideoSeek) {
|
||||||
@"seekTime": [NSNumber numberWithFloat:seekTime],
|
self.onVideoSeek(@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
|
||||||
@"target": self.reactTag});
|
@"seekTime": [NSNumber numberWithFloat:seekTime],
|
||||||
|
@"target": self.reactTag});
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
_pendingSeek = false;
|
_pendingSeek = false;
|
||||||
@ -573,11 +589,15 @@ static NSString *const playbackRate = @"rate";
|
|||||||
if( viewController )
|
if( viewController )
|
||||||
{
|
{
|
||||||
_presentingViewController = viewController;
|
_presentingViewController = viewController;
|
||||||
self.onVideoFullscreenPlayerWillPresent(@{@"target": self.reactTag});
|
if(self.onVideoFullscreenPlayerWillPresent) {
|
||||||
|
self.onVideoFullscreenPlayerWillPresent(@{@"target": self.reactTag});
|
||||||
|
}
|
||||||
[viewController presentViewController:_playerViewController animated:true completion:^{
|
[viewController presentViewController:_playerViewController animated:true completion:^{
|
||||||
_playerViewController.showsPlaybackControls = YES;
|
_playerViewController.showsPlaybackControls = YES;
|
||||||
_fullscreenPlayerPresented = fullscreen;
|
_fullscreenPlayerPresented = fullscreen;
|
||||||
self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag});
|
if(self.onVideoFullscreenPlayerDidPresent) {
|
||||||
|
self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag});
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -655,7 +675,7 @@ static NSString *const playbackRate = @"rate";
|
|||||||
|
|
||||||
- (void)videoPlayerViewControllerWillDismiss:(AVPlayerViewController *)playerViewController
|
- (void)videoPlayerViewControllerWillDismiss:(AVPlayerViewController *)playerViewController
|
||||||
{
|
{
|
||||||
if (_playerViewController == playerViewController && _fullscreenPlayerPresented)
|
if (_playerViewController == playerViewController && _fullscreenPlayerPresented && self.onVideoFullscreenPlayerWillDismiss)
|
||||||
{
|
{
|
||||||
self.onVideoFullscreenPlayerWillDismiss(@{@"target": self.reactTag});
|
self.onVideoFullscreenPlayerWillDismiss(@{@"target": self.reactTag});
|
||||||
}
|
}
|
||||||
@ -668,7 +688,9 @@ static NSString *const playbackRate = @"rate";
|
|||||||
_fullscreenPlayerPresented = false;
|
_fullscreenPlayerPresented = false;
|
||||||
_presentingViewController = nil;
|
_presentingViewController = nil;
|
||||||
[self applyModifiers];
|
[self applyModifiers];
|
||||||
self.onVideoFullscreenPlayerDidDismiss(@{@"target": self.reactTag});
|
if(self.onVideoFullscreenPlayerDidDismiss) {
|
||||||
|
self.onVideoFullscreenPlayerDidDismiss(@{@"target": self.reactTag});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user