-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoSeq.js
49 lines (38 loc) · 1.07 KB
/
VideoSeq.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
import React from 'react';
import PropTypes from 'prop-types';
import Video from 'react-native-video';
class VideoSeq extends React.Component {
constructor(props) {
super(props);
this.onEnd = this.onEnd.bind(this);
this.state = {
curVidIndex: 0,
};
}
onEnd(event) {
// Call user defined onEnd func if it exists
if (this.props.onEnd) {
this.props.onEnd(event);
}
// Switch to the next video in the sequence
let curVidIndex = this.state.curVidIndex + 1;
if(curVidIndex == this.props.videos.length) {
// Reset to first vid if repeat is on
curVidIndex = this.props.repeat ? 0 : this.state.curVidIndex;
}
this.setState({curVidIndex});
}
render() {
const curVid = this.props.videos[this.state.curVidIndex];
const { source, repeat, onEnd, ...passThroughProps } = this.props;
passThroughProps.onEnd = this.onEnd;
return (
<Video source={curVid} {...passThroughProps} />
)
}
}
VideoSeq.propTypes = {
videos: PropTypes.array.isRequired,
...Video.propTypes
};
export default VideoSeq;