From 83dd4c3ba9e91aefe90fff3dd95fcc40a0e5999c Mon Sep 17 00:00:00 2001 From: Edward Chan Date: Tue, 6 Sep 2016 19:23:13 -0700 Subject: [PATCH] add seekableDuration (#285) --- RCTVideo.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index 6964bf34..f784bad5 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -110,6 +110,17 @@ static NSString *const playbackRate = @"rate"; return(kCMTimeInvalid); } +- (CMTimeRange)playerItemSeekableTimeRange +{ + AVPlayerItem *playerItem = [_player currentItem]; + if (playerItem.status == AVPlayerItemStatusReadyToPlay) + { + return [playerItem seekableTimeRanges].firstObject.CMTimeRangeValue; + } + + return (kCMTimeRangeZero); +} + /* Cancels the previously registered time observer. */ -(void)removePlayerTimeObserver @@ -173,14 +184,15 @@ static NSString *const playbackRate = @"rate"; CMTime currentTime = _player.currentTime; const Float64 duration = CMTimeGetSeconds(playerDuration); const Float64 currentTimeSecs = CMTimeGetSeconds(currentTime); - if( currentTimeSecs >= 0 && currentTimeSecs <= duration) { + if( currentTimeSecs >= 0) { [_eventDispatcher sendInputEventWithName:@"onVideoProgress" body:@{ @"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(currentTime)], @"playableDuration": [self calculatePlayableDuration], @"atValue": [NSNumber numberWithLongLong:currentTime.value], @"atTimescale": [NSNumber numberWithInt:currentTime.timescale], - @"target": self.reactTag + @"target": self.reactTag, + @"seekableDuration": [NSNumber numberWithFloat:CMTimeGetSeconds([self playerItemSeekableTimeRange].duration)], }]; } }