diff --git a/Video.js b/Video.js index 29aa5154..979eabb3 100644 --- a/Video.js +++ b/Video.js @@ -1,6 +1,6 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; -import {StyleSheet, requireNativeComponent, NativeModules, View, ViewPropTypes, Image} from 'react-native'; +import {StyleSheet, requireNativeComponent, NativeModules, View, ViewPropTypes, Image, Platform} from 'react-native'; import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource'; import TextTrackType from './TextTrackType'; import VideoResizeMode from './VideoResizeMode.js'; @@ -27,8 +27,17 @@ export default class Video extends Component { this._root.setNativeProps(nativeProps); } - seek = (time) => { - this.setNativeProps({ seek: time }); + seek = (time, tolerance = 100) => { + if (Platform.OS === 'ios') { + this.setNativeProps({ + seek: { + time, + tolerance + } + }); + } else { + this.setNativeProps({ seek: time }); + } }; presentFullscreenPlayer = () => { @@ -250,7 +259,10 @@ export default class Video extends Component { Video.propTypes = { /* Native only */ src: PropTypes.object, - seek: PropTypes.number, + seek: PropTypes.oneOfType([ + PropTypes.number, + PropTypes.object + ]), fullscreen: PropTypes.bool, onVideoLoadStart: PropTypes.func, onVideoLoad: PropTypes.func, diff --git a/ios/RCTVideo.m b/ios/RCTVideo.m index a9734f7d..97b40c1e 100644 --- a/ios/RCTVideo.m +++ b/ios/RCTVideo.m @@ -569,21 +569,28 @@ static NSString *const timedMetadata = @"timedMetadata"; - (void)setCurrentTime:(float)currentTime { - [self setSeek: currentTime]; + NSDictionary *info = @{ + @"time": [NSNumber numberWithFloat:currentTime], + @"tolerance": [NSNumber numberWithInt:100] + }; + [self setSeek:info]; } -- (void)setSeek:(float)seekTime +- (void)setSeek:(NSDictionary *)info { - int timeScale = 10000; + NSNumber *seekTime = info[@"time"]; + NSNumber *seekTolerance = info[@"tolerance"]; + + int timeScale = 1000; AVPlayerItem *item = _player.currentItem; if (item && item.status == AVPlayerItemStatusReadyToPlay) { // TODO check loadedTimeRanges - CMTime cmSeekTime = CMTimeMakeWithSeconds(seekTime, timeScale); + CMTime cmSeekTime = CMTimeMakeWithSeconds([seekTime floatValue], timeScale); CMTime current = item.currentTime; // TODO figure out a good tolerance level - CMTime tolerance = CMTimeMake(1000, timeScale); + CMTime tolerance = CMTimeMake([seekTolerance floatValue], timeScale); BOOL wasPaused = _paused; if (CMTimeCompare(current, cmSeekTime) != 0) { @@ -593,11 +600,11 @@ static NSString *const timedMetadata = @"timedMetadata"; [self addPlayerTimeObserver]; } if (!wasPaused) { - [self setPaused:false]; + [self setPaused:false]; } if(self.onVideoSeek) { self.onVideoSeek(@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)], - @"seekTime": [NSNumber numberWithFloat:seekTime], + @"seekTime": seekTime, @"target": self.reactTag}); } }]; @@ -608,7 +615,7 @@ static NSString *const timedMetadata = @"timedMetadata"; } else { // TODO: See if this makes sense and if so, actually implement it _pendingSeek = true; - _pendingSeekTime = seekTime; + _pendingSeekTime = [seekTime floatValue]; } } diff --git a/ios/RCTVideoManager.m b/ios/RCTVideoManager.m index e801447d..3f12e71c 100644 --- a/ios/RCTVideoManager.m +++ b/ios/RCTVideoManager.m @@ -32,7 +32,7 @@ RCT_EXPORT_VIEW_PROPERTY(playInBackground, BOOL); RCT_EXPORT_VIEW_PROPERTY(playWhenInactive, BOOL); RCT_EXPORT_VIEW_PROPERTY(ignoreSilentSwitch, NSString); RCT_EXPORT_VIEW_PROPERTY(rate, float); -RCT_EXPORT_VIEW_PROPERTY(seek, float); +RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary); RCT_EXPORT_VIEW_PROPERTY(currentTime, float); RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL); RCT_EXPORT_VIEW_PROPERTY(progressUpdateInterval, float);