/
VideoPlayer.js
81 lines (75 loc) · 1.74 KB
/
VideoPlayer.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
import React, { PropTypes, Component } from 'react';
import {
View,
requireNativeComponent,
NativeModules
} from 'react-native';
import { getActualSource } from '../utils';
const PLAYER_COMPONENT_NAME = 'RNVideoProcessing';
const { RNVideoTrimmer } = NativeModules;
export class VideoPlayer extends Component {
static propTypes = {
source: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
play: PropTypes.bool,
currentTime: PropTypes.number,
volume: PropTypes.number,
startTime: PropTypes.number,
background_Color: PropTypes.string,
endTime: PropTypes.number,
playerWidth: PropTypes.number,
playerHeight: PropTypes.number,
...View.propTypes
};
static defaultProps = {
play: false,
volume: 0.0,
currentTime: 0,
startTime: 0,
};
constructor(...args) {
super(...args);
this.state = {};
this.trim = this.trim.bind(this);
}
trim(source, start, end) {
const actualSource = getActualSource(source);
return new Promise((resolve, reject) => {
RNVideoTrimmer.trim(actualSource, start, end, (err, output) => {
if (err) {
return reject(err);
}
return resolve(output);
});
});
}
render() {
const {
source,
play,
currentTime,
backgroundColor,
startTime,
endTime,
playerWidth,
playerHeight,
volume,
...viewProps
} = this.props;
const actualSource = getActualSource(source);
return (
<RNVideoPlayer
source={actualSource}
play={play}
volume={volume}
playerWidth={playerWidth}
playerHeight={playerHeight}
currentTime={currentTime}
background_Color={backgroundColor}
startTime={startTime}
endTime={endTime}
{...viewProps}
/>
);
}
}
const RNVideoPlayer = requireNativeComponent(PLAYER_COMPONENT_NAME, VideoPlayer);