Using completion handler to trigger seek event now, in order to receive correct currentTime value

This commit is contained in:
Johannes Lumpe 2015-04-09 17:19:09 +03:00
parent 380c1d46cc
commit 29d4a4fda2

View File

@ -136,6 +136,7 @@ static NSString *const statusKeyPath = @"status";
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == _playerItem) { if (object == _playerItem) {
if (_playerItem.status == AVPlayerItemStatusReadyToPlay) { if (_playerItem.status == AVPlayerItemStatusReadyToPlay) {
// 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)],
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)], @"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)],
@ -202,13 +203,15 @@ static NSString *const statusKeyPath = @"status";
CMTime tolerance = CMTimeMake(1000, timeScale); CMTime tolerance = CMTimeMake(1000, timeScale);
if (CMTimeCompare(current, cmSeekTime) != 0) { if (CMTimeCompare(current, cmSeekTime) != 0) {
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance]; [_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
_pendingSeek = false; [_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{
[_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{ @"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)], @"seekTime": [NSNumber numberWithFloat:seekTime],
@"seekTime": [NSNumber numberWithFloat:seekTime], @"target": self.reactTag
@"target": self.reactTag }];
}]; }];
_pendingSeek = false;
} }
} else { } else {