-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
129 lines (114 loc) · 2.76 KB
/
index.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import React from 'react';
import {
View,
Platform,
StyleSheet,
NativeModules,
findNodeHandle,
requireNativeComponent,
} from 'react-native';
import PropTypes from 'prop-types';
export default class ApsaraPlayer extends React.Component {
get _module() {
return Platform.OS === 'ios'
? NativeModules.ApsaraPlayerManager
: NativeModules.ApsaraPlayerModule;
}
componentWillUnmount() {
this._module.destroy(findNodeHandle(this._player));
}
setNativeProps(nativeProps) {
this._player.setNativeProps(nativeProps);
}
seek = time => {
if (isNaN(time)) throw new Error('Specified time is not a number');
this.setNativeProps({seek: time});
};
_onLoad = event => {
if (this.props.onLoad) {
this.props.onLoad(event.nativeEvent);
}
};
_onError = event => {
if (this.props.onError) {
this.props.onError(event.nativeEvent);
}
};
_onProgress = event => {
if (this.props.onProgress) {
this.props.onProgress(event.nativeEvent);
}
};
_onSeek = event => {
if (this.props.onSeek) {
this.props.onSeek(event.nativeEvent);
}
};
save = options => {
return this._module.save(options, findNodeHandle(this._player));
};
render() {
const style = [styles.base, this.props.style];
return (
<View style={style}>
<RNApsaraPlayer
ref={r => {
this._player = r;
}}
style={StyleSheet.absoluteFill}
source={this.props.source}
paused={this.props.paused}
volume={this.props.volume}
muted={this.props.muted}
onVideoEnd={this.props.onEnd}
onVideoLoad={this._onLoad}
onVideoSeek={this._onSeek}
onVideoError={this._onError}
onVideoProgress={this._onProgress}
/>
</View>
);
}
}
ApsaraPlayer.defaultProps = {
volume: 1,
muted: false,
paused: false,
repeat: false,
}
ApsaraPlayer.propTypes = {
repeat: PropTypes.bool,
paused: PropTypes.bool,
muted: PropTypes.bool,
volume: PropTypes.number,
source: PropTypes.shape({
uri: PropTypes.string,
sts: PropTypes.shape({
vid: PropTypes.string,
region: PropTypes.string,
accessKeyId: PropTypes.string,
accessKeySecret: PropTypes.string,
securityToken: PropTypes.string,
}),
auth: PropTypes.shape({
vid: PropTypes.string,
region: PropTypes.string,
playAuth: PropTypes.string,
}),
}),
onEnd: PropTypes.func,
onLoad: PropTypes.func,
onSeek: PropTypes.func,
onError: PropTypes.func,
onProgress: PropTypes.func,
};
const styles = StyleSheet.create({
base: {
overflow: 'hidden',
},
});
const RNApsaraPlayer = requireNativeComponent('ApsaraPlayer', ApsaraPlayer, {
nativeOnly: {
seek: true,
},
});