add seekableDuration (#285)

This commit is contained in:
Edward Chan 2016-09-06 19:23:13 -07:00 committed by Matt Apperson
parent 3130bce6bd
commit 83dd4c3ba9

View File

@ -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)],
}];
}
}