Made seek a float value again, now triggered through this.refs.myVideoNode.seek(time)

This commit is contained in:
Johannes Lumpe 2015-04-09 16:50:20 +03:00
parent 45d79b701e
commit 380c1d46cc
3 changed files with 10 additions and 23 deletions

View File

@ -189,19 +189,8 @@ static NSString *const statusKeyPath = @"status";
} }
} }
- (void)setSeek:(NSDictionary*)seek { - (void)setSeek:(float)seekTime {
NSNumber *seekValue = [seek objectForKey:@"time"];
if (!seekValue) {
return;
}
int timeScale = 10000; int timeScale = 10000;
float seekTime = [RCTConvert float:seekValue];
bool force = [RCTConvert BOOL:[seek objectForKey:@"force"]];
if (seekTime == _lastSeekTime && !force) {
return;
}
AVPlayerItem *item = _player.currentItem; AVPlayerItem *item = _player.currentItem;
if (item && item.status == AVPlayerItemStatusReadyToPlay) { if (item && item.status == AVPlayerItemStatusReadyToPlay) {
@ -211,14 +200,13 @@ static NSString *const statusKeyPath = @"status";
CMTime current = item.currentTime; CMTime current = item.currentTime;
// TODO figure out a good tolerance level // TODO figure out a good tolerance level
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];
_pendingSeek = false; _pendingSeek = false;
_lastSeekTime = seekTime;
[_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{ [_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)], @"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
@"seekTime": seekValue, @"seekTime": [NSNumber numberWithFloat:seekTime],
@"target": self.reactTag @"target": self.reactTag
}]; }];
} }

View File

@ -42,7 +42,7 @@ RCT_EXPORT_VIEW_PROPERTY(paused, BOOL);
RCT_EXPORT_VIEW_PROPERTY(muted, BOOL); RCT_EXPORT_VIEW_PROPERTY(muted, BOOL);
RCT_EXPORT_VIEW_PROPERTY(volume, float); RCT_EXPORT_VIEW_PROPERTY(volume, float);
RCT_EXPORT_VIEW_PROPERTY(rate, float); RCT_EXPORT_VIEW_PROPERTY(rate, float);
RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary); RCT_EXPORT_VIEW_PROPERTY(seek, float);
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {

View File

@ -21,7 +21,6 @@ var Video = React.createClass({
resizeMode: PropTypes.string, resizeMode: PropTypes.string,
repeat: PropTypes.bool, repeat: PropTypes.bool,
paused: PropTypes.bool, paused: PropTypes.bool,
seek: PropTypes.number,
muted: PropTypes.bool, muted: PropTypes.bool,
volume: PropTypes.number, volume: PropTypes.number,
rate: PropTypes.number, rate: PropTypes.number,
@ -58,6 +57,10 @@ var Video = React.createClass({
this.props.onSeek && this.props.onSeek(event.nativeEvent); this.props.onSeek && this.props.onSeek(event.nativeEvent);
}, },
seek(time) {
this.refs.video.setNativeProps({seek: parseFloat(time)});
},
render() { render() {
var style = flattenStyle([styles.base, this.props.style]); var style = flattenStyle([styles.base, this.props.style]);
var source = this.props.source; var source = this.props.source;
@ -76,10 +79,6 @@ var Video = React.createClass({
} }
var nativeProps = merge(this.props, { var nativeProps = merge(this.props, {
seek: {
time: this.props.seek,
force: this.props.forceSeek
},
style, style,
resizeMode: resizeMode, resizeMode: resizeMode,
src: { src: {
@ -92,14 +91,14 @@ var Video = React.createClass({
onProgress: this._onProgress, onProgress: this._onProgress,
}); });
return <RCTVideo {... nativeProps} /> return <RCTVideo ref="video" {... nativeProps} />
}, },
}); });
var RCTVideo = createReactIOSNativeComponentClass({ var RCTVideo = createReactIOSNativeComponentClass({
validAttributes: merge(ReactIOSViewAttributes.UIView, validAttributes: merge(ReactIOSViewAttributes.UIView,
{src: {diff: deepDiffer}, resizeMode: true, repeat: true, {src: {diff: deepDiffer}, resizeMode: true, repeat: true,
seek: {diff: () => true}, paused: true, muted: true, volume: true, rate: true}), seek: true, paused: true, muted: true, volume: true, rate: true}),
uiViewClassName: 'RCTVideo', uiViewClassName: 'RCTVideo',
}); });