2015-04-06 13:17:32 -06:00
|
|
|
var React = require('react-native');
|
2015-06-24 22:26:36 -06:00
|
|
|
var { requireNativeComponent, } = React;
|
2015-05-14 19:10:41 -06:00
|
|
|
var ReactNativeViewAttributes = require('ReactNativeViewAttributes');
|
2015-06-24 22:26:36 -06:00
|
|
|
var NativeModules = require('NativeModules');
|
2015-03-30 23:07:55 -06:00
|
|
|
var StyleSheet = require('StyleSheet');
|
|
|
|
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-06-24 22:26:36 -06:00
|
|
|
/* Native only */
|
|
|
|
src: PropTypes.object,
|
|
|
|
seek: PropTypes.number,
|
|
|
|
|
|
|
|
/* Wrapper component */
|
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-04-10 21:40:13 -06:00
|
|
|
onEnd: PropTypes.func,
|
2015-03-30 23:07:55 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [NativeMethodsMixin],
|
|
|
|
|
|
|
|
viewConfig: {
|
|
|
|
uiViewClassName: 'UIView',
|
2015-05-14 19:10:41 -06:00
|
|
|
validAttributes: ReactNativeViewAttributes.UIView
|
2015-03-30 23:07:55 -06:00
|
|
|
},
|
|
|
|
|
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) {
|
2015-04-09 09:12:54 -06:00
|
|
|
this.setNativeProps({seek: parseFloat(time)});
|
2015-04-09 07:50:20 -06:00
|
|
|
},
|
|
|
|
|
2015-04-10 21:40:13 -06:00
|
|
|
_onEnd(event) {
|
|
|
|
this.props.onEnd && this.props.onEnd(event.nativeEvent);
|
|
|
|
},
|
|
|
|
|
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-06-14 11:31:39 -06:00
|
|
|
var uri = source.uri;
|
|
|
|
if (uri && uri.match(/^\//)) {
|
|
|
|
uri = 'file://' + uri;
|
|
|
|
}
|
|
|
|
var isNetwork = !!(uri && uri.match(/^https?:/));
|
|
|
|
var isAsset = !!(uri && uri.match(/^(assets-library|file):/));
|
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: {
|
2015-06-14 11:31:39 -06:00
|
|
|
uri: uri,
|
2015-04-08 00:49:14 -06:00
|
|
|
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-04-10 21:40:13 -06:00
|
|
|
onEnd: this._onEnd,
|
2015-03-30 23:07:55 -06:00
|
|
|
});
|
|
|
|
|
2015-04-09 09:12:54 -06:00
|
|
|
return <RCTVideo {... nativeProps} />;
|
2015-03-30 23:07:55 -06:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-06-24 22:26:36 -06:00
|
|
|
var RCTVideo = requireNativeComponent('RCTVideo', Video);
|
2015-03-30 23:07:55 -06:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
base: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Video;
|