Provide a fallback if the duration cannot be get

This to avoid to send an errors stack caused by the `NaN` given in the JSON of the RCTEventDispatcher.

fixes #26
This commit is contained in:
Gaël Gillard 2015-04-28 12:00:38 +02:00 committed by Brent Vatne
parent 2b5fc21caf
commit ce7f82b884

View File

@ -145,7 +145,7 @@ static NSString *const statusKeyPath = @"status";
if (_playerItem.status == AVPlayerItemStatusReadyToPlay) { if (_playerItem.status == AVPlayerItemStatusReadyToPlay) {
// NSLog(@"duration: %f",CMTimeGetSeconds(_playerItem.asset.duration)); // NSLog(@"duration: %f",CMTimeGetSeconds(_playerItem.asset.duration));
[_eventDispatcher sendInputEventWithName:RNVideoEventLoaded body:@{ [_eventDispatcher sendInputEventWithName:RNVideoEventLoaded body:@{
@"duration": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.duration)], @"duration": [NSNumber numberWithFloat:(CMTimeGetSeconds(_playerItem.duration) || 0.0)],
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)], @"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)],
@"canPlayReverse": [NSNumber numberWithBool:_playerItem.canPlayReverse], @"canPlayReverse": [NSNumber numberWithBool:_playerItem.canPlayReverse],
@"canPlayFastForward": [NSNumber numberWithBool:_playerItem.canPlayFastForward], @"canPlayFastForward": [NSNumber numberWithBool:_playerItem.canPlayFastForward],