forked from TheWidlarzGroup/react-native-video
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Video.ios.js
109 lines (90 loc) · 2.71 KB
/
Video.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var React = require('react-native');
var { StyleSheet, requireNativeComponent, PropTypes, NativeModules, } = React;
var VideoResizeMode = require('./VideoResizeMode');
var merge = require('merge');
var VIDEO_REF = 'video';
var Video = React.createClass({
propTypes: {
/* Native only */
src: PropTypes.object,
seek: PropTypes.number,
/* Wrapper component */
source: PropTypes.object,
resizeMode: PropTypes.string,
repeat: PropTypes.bool,
paused: PropTypes.bool,
muted: PropTypes.bool,
volume: PropTypes.number,
rate: PropTypes.number,
onLoadStart: PropTypes.func,
onLoad: PropTypes.func,
onError: PropTypes.func,
onProgress: PropTypes.func,
onEnd: PropTypes.func,
},
setNativeProps(props) {
this.refs[VIDEO_REF].setNativeProps(props);
},
_onLoadStart(event) {
this.props.onLoadStart && this.props.onLoadStart(event.nativeEvent);
},
_onLoad(event) {
this.props.onLoad && this.props.onLoad(event.nativeEvent);
},
_onError(event) {
this.props.onError && this.props.onError(event.nativeEvent);
},
_onProgress(event) {
this.props.onProgress && this.props.onProgress(event.nativeEvent);
},
_onSeek(event) {
this.props.onSeek && this.props.onSeek(event.nativeEvent);
},
seek(time) {
this.setNativeProps({seek: parseFloat(time)});
},
_onEnd(event) {
this.props.onEnd && this.props.onEnd(event.nativeEvent);
},
render() {
var style = [styles.base, this.props.style];
var source = this.props.source;
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):/));
var resizeMode;
if (this.props.resizeMode === VideoResizeMode.stretch) {
resizeMode = NativeModules.VideoManager.ScaleToFill;
} else if (this.props.resizeMode === VideoResizeMode.contain) {
resizeMode = NativeModules.VideoManager.ScaleAspectFit;
} else if (this.props.resizeMode === VideoResizeMode.cover) {
resizeMode = NativeModules.VideoManager.ScaleAspectFill;
} else {
resizeMode = NativeModules.VideoManager.ScaleNone;
}
var nativeProps = merge({},this.props, {
style,
resizeMode: resizeMode,
src: {
uri: uri,
isNetwork,
isAsset,
type: source.type || 'mp4'
},
onVideoLoad: this._onLoad,
onVideoProgress: this._onProgress,
onVideoEnd: this._onEnd,
});
return <RCTVideo ref={VIDEO_REF} {... nativeProps} />;
},
});
var RCTVideo = requireNativeComponent('RCTVideo', Video);
var styles = StyleSheet.create({
base: {
overflow: 'hidden',
},
});
module.exports = Video;