2015-04-06 13:17:32 -06:00
|
|
|
var React = require('react-native');
|
2015-03-30 23:07:55 -06:00
|
|
|
var NativeModules = require('NativeModules');
|
|
|
|
var ReactIOSViewAttributes = require('ReactIOSViewAttributes');
|
|
|
|
var StyleSheet = require('StyleSheet');
|
|
|
|
var createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass');
|
|
|
|
var PropTypes = require('ReactPropTypes');
|
|
|
|
var StyleSheetPropType = require('StyleSheetPropType');
|
|
|
|
var VideoResizeMode = require('./VideoResizeMode');
|
|
|
|
var VideoStylePropTypes = require('./VideoStylePropTypes');
|
|
|
|
var NativeMethodsMixin = require('NativeMethodsMixin');
|
|
|
|
var flattenStyle = require('flattenStyle');
|
|
|
|
var merge = require('merge');
|
2015-04-08 00:49:14 -06:00
|
|
|
var deepDiffer = require('deepDiffer');
|
2015-03-30 23:07:55 -06:00
|
|
|
|
|
|
|
var Video = React.createClass({
|
|
|
|
propTypes: {
|
2015-04-08 09:44:28 -06:00
|
|
|
// should probably be a shape
|
|
|
|
source: PropTypes.object,
|
2015-03-30 23:07:55 -06:00
|
|
|
style: StyleSheetPropType(VideoStylePropTypes),
|
2015-04-08 00:49:14 -06:00
|
|
|
source: PropTypes.object,
|
2015-04-05 11:17:03 -06:00
|
|
|
resizeMode: PropTypes.string,
|
2015-03-31 00:29:15 -06:00
|
|
|
repeat: PropTypes.bool,
|
2015-04-07 21:38:16 -06:00
|
|
|
paused: PropTypes.bool,
|
|
|
|
muted: PropTypes.bool,
|
|
|
|
volume: PropTypes.number,
|
|
|
|
rate: PropTypes.number,
|
2015-04-08 00:49:14 -06:00
|
|
|
onLoadStart: PropTypes.func,
|
2015-04-06 13:17:32 -06:00
|
|
|
onLoad: PropTypes.func,
|
2015-04-08 00:49:14 -06:00
|
|
|
onError: PropTypes.func,
|
2015-04-06 14:05:05 -06:00
|
|
|
onProgress: PropTypes.func,
|
2015-03-30 23:07:55 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [NativeMethodsMixin],
|
|
|
|
|
|
|
|
viewConfig: {
|
|
|
|
uiViewClassName: 'UIView',
|
|
|
|
validAttributes: ReactIOSViewAttributes.UIView
|
|
|
|
},
|
|
|
|
|
2015-04-08 00:49:14 -06:00
|
|
|
_onLoadStart(event) {
|
|
|
|
this.props.onLoadStart && this.props.onLoadStart(event.nativeEvent);
|
|
|
|
},
|
|
|
|
|
2015-04-06 13:17:32 -06:00
|
|
|
_onLoad(event) {
|
|
|
|
this.props.onLoad && this.props.onLoad(event.nativeEvent);
|
|
|
|
},
|
|
|
|
|
2015-04-08 00:49:14 -06:00
|
|
|
_onError(event) {
|
|
|
|
this.props.onError && this.props.onError(event.nativeEvent);
|
|
|
|
},
|
|
|
|
|
2015-04-06 14:05:05 -06:00
|
|
|
_onProgress(event) {
|
|
|
|
this.props.onProgress && this.props.onProgress(event.nativeEvent);
|
|
|
|
},
|
|
|
|
|
2015-04-08 16:15:57 -06:00
|
|
|
_onSeek(event) {
|
|
|
|
this.props.onSeek && this.props.onSeek(event.nativeEvent);
|
|
|
|
},
|
|
|
|
|
2015-04-09 07:50:20 -06:00
|
|
|
seek(time) {
|
|
|
|
this.refs.video.setNativeProps({seek: parseFloat(time)});
|
|
|
|
},
|
|
|
|
|
2015-04-06 13:17:32 -06:00
|
|
|
render() {
|
2015-03-30 23:07:55 -06:00
|
|
|
var style = flattenStyle([styles.base, this.props.style]);
|
|
|
|
var source = this.props.source;
|
2015-04-08 00:49:14 -06:00
|
|
|
var isNetwork = !!(source.uri && source.uri.match(/^https?:/));
|
2015-04-08 09:44:28 -06:00
|
|
|
var isAsset = !!(source.uri && source.uri.match(/^assets-library:/));
|
2015-03-30 23:07:55 -06:00
|
|
|
|
|
|
|
var resizeMode;
|
2015-04-05 11:17:03 -06:00
|
|
|
if (this.props.resizeMode === VideoResizeMode.stretch) {
|
|
|
|
resizeMode = NativeModules.VideoManager.ScaleToFill;
|
|
|
|
} else if (this.props.resizeMode === VideoResizeMode.contain) {
|
|
|
|
resizeMode = NativeModules.VideoManager.ScaleAspectFit;
|
2015-04-08 09:44:28 -06:00
|
|
|
} else if (this.props.resizeMode === VideoResizeMode.cover) {
|
2015-04-05 11:17:03 -06:00
|
|
|
resizeMode = NativeModules.VideoManager.ScaleAspectFill;
|
2015-03-30 23:07:55 -06:00
|
|
|
} else {
|
2015-04-05 11:17:03 -06:00
|
|
|
resizeMode = NativeModules.VideoManager.ScaleNone;
|
2015-03-30 23:07:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var nativeProps = merge(this.props, {
|
|
|
|
style,
|
2015-04-05 11:17:03 -06:00
|
|
|
resizeMode: resizeMode,
|
2015-04-08 00:49:14 -06:00
|
|
|
src: {
|
|
|
|
uri: source.uri,
|
|
|
|
isNetwork,
|
2015-04-08 09:44:28 -06:00
|
|
|
isAsset,
|
2015-04-08 00:49:14 -06:00
|
|
|
type: source.type || 'mp4'
|
|
|
|
},
|
2015-04-06 13:17:32 -06:00
|
|
|
onLoad: this._onLoad,
|
2015-04-06 14:05:05 -06:00
|
|
|
onProgress: this._onProgress,
|
2015-03-30 23:07:55 -06:00
|
|
|
});
|
|
|
|
|
2015-04-09 07:50:20 -06:00
|
|
|
return <RCTVideo ref="video" {... nativeProps} />
|
2015-03-30 23:07:55 -06:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
var RCTVideo = createReactIOSNativeComponentClass({
|
2015-04-05 11:17:03 -06:00
|
|
|
validAttributes: merge(ReactIOSViewAttributes.UIView,
|
2015-04-08 11:34:27 -06:00
|
|
|
{src: {diff: deepDiffer}, resizeMode: true, repeat: true,
|
2015-04-09 07:50:20 -06:00
|
|
|
seek: true, paused: true, muted: true, volume: true, rate: true}),
|
2015-03-30 23:07:55 -06:00
|
|
|
uiViewClassName: 'RCTVideo',
|
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
base: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Video;
|