2015-04-08 13:01:10 -06:00
|
|
|
'use strict';
|
2016-02-10 04:39:54 -07:00
|
|
|
import React, {
|
2016-04-21 22:01:44 -06:00
|
|
|
Component
|
|
|
|
} from 'react';
|
|
|
|
|
|
|
|
import {
|
2016-02-10 04:39:54 -07:00
|
|
|
AlertIOS,
|
2015-04-08 13:01:10 -06:00
|
|
|
AppRegistry,
|
2017-04-20 12:10:06 -06:00
|
|
|
Platform,
|
2015-04-08 13:01:10 -06:00
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableOpacity,
|
2016-02-10 04:39:54 -07:00
|
|
|
View,
|
|
|
|
} from 'react-native';
|
2015-04-08 13:01:10 -06:00
|
|
|
|
2018-12-13 20:30:38 -07:00
|
|
|
import Video,{FilterType} from 'react-native-video';
|
|
|
|
|
2019-12-09 21:40:49 -07:00
|
|
|
const adTagUrl = "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/"
|
|
|
|
+ "ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp"
|
|
|
|
+ "&output=vmap&unviewed_position_start=1&cust_params=deployment%3Ddevsite"
|
|
|
|
+ "%26sample_ar%3Dpremidpost&cmsid=496&vid=short_onecue&correlator=";
|
|
|
|
|
2018-12-13 20:30:38 -07:00
|
|
|
const filterTypes = [
|
|
|
|
FilterType.NONE,
|
|
|
|
FilterType.INVERT,
|
|
|
|
FilterType.MONOCHROME,
|
|
|
|
FilterType.POSTERIZE,
|
|
|
|
FilterType.FALSE,
|
|
|
|
FilterType.MAXIMUMCOMPONENT,
|
|
|
|
FilterType.MINIMUMCOMPONENT,
|
|
|
|
FilterType.CHROME,
|
|
|
|
FilterType.FADE,
|
|
|
|
FilterType.INSTANT,
|
|
|
|
FilterType.MONO,
|
|
|
|
FilterType.NOIR,
|
|
|
|
FilterType.PROCESS,
|
|
|
|
FilterType.TONAL,
|
|
|
|
FilterType.TRANSFER,
|
|
|
|
FilterType.SEPIA
|
|
|
|
];
|
2016-02-10 04:39:54 -07:00
|
|
|
|
|
|
|
class VideoPlayer extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.onLoad = this.onLoad.bind(this);
|
|
|
|
this.onProgress = this.onProgress.bind(this);
|
2017-01-11 05:51:45 -07:00
|
|
|
this.onBuffer = this.onBuffer.bind(this);
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
|
|
|
state = {
|
|
|
|
rate: 1,
|
|
|
|
volume: 1,
|
|
|
|
muted: false,
|
|
|
|
resizeMode: 'contain',
|
|
|
|
duration: 0.0,
|
|
|
|
currentTime: 0.0,
|
|
|
|
controls: false,
|
|
|
|
paused: true,
|
2017-01-11 05:51:45 -07:00
|
|
|
skin: 'custom',
|
2017-04-20 12:10:06 -06:00
|
|
|
ignoreSilentSwitch: null,
|
2017-01-11 05:51:45 -07:00
|
|
|
isBuffering: false,
|
2018-12-13 20:30:38 -07:00
|
|
|
filter: FilterType.NONE,
|
|
|
|
filterEnabled: true
|
2016-02-10 04:39:54 -07:00
|
|
|
};
|
2016-04-12 12:31:05 -06:00
|
|
|
|
2015-04-08 13:01:10 -06:00
|
|
|
onLoad(data) {
|
2017-01-11 05:43:43 -07:00
|
|
|
console.log('On load fired!');
|
2015-04-08 13:01:10 -06:00
|
|
|
this.setState({duration: data.duration});
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
2015-04-08 13:01:10 -06:00
|
|
|
|
|
|
|
onProgress(data) {
|
|
|
|
this.setState({currentTime: data.currentTime});
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
2015-04-08 13:01:10 -06:00
|
|
|
|
2017-01-11 05:51:45 -07:00
|
|
|
onBuffer({ isBuffering }: { isBuffering: boolean }) {
|
|
|
|
this.setState({ isBuffering });
|
|
|
|
}
|
|
|
|
|
2015-04-08 13:01:10 -06:00
|
|
|
getCurrentTimePercentage() {
|
|
|
|
if (this.state.currentTime > 0) {
|
|
|
|
return parseFloat(this.state.currentTime) / parseFloat(this.state.duration);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
2015-04-08 13:01:10 -06:00
|
|
|
|
2018-12-13 20:30:38 -07:00
|
|
|
setFilter(step) {
|
|
|
|
let index = filterTypes.indexOf(this.state.filter) + step;
|
|
|
|
|
|
|
|
if (index === filterTypes.length) {
|
|
|
|
index = 0;
|
|
|
|
} else if (index === -1) {
|
|
|
|
index = filterTypes.length - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
filter: filterTypes[index]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-12-22 16:39:04 -07:00
|
|
|
renderSkinControl(skin) {
|
2016-02-10 04:39:54 -07:00
|
|
|
const isSelected = this.state.skin == skin;
|
|
|
|
const selectControls = skin == 'native' || skin == 'embed';
|
2015-12-22 16:39:04 -07:00
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={() => { this.setState({
|
|
|
|
controls: selectControls,
|
|
|
|
skin: skin
|
|
|
|
}) }}>
|
|
|
|
<Text style={[styles.controlOption, {fontWeight: isSelected ? "bold" : "normal"}]}>
|
|
|
|
{skin}
|
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
2015-12-22 16:39:04 -07:00
|
|
|
|
2015-04-08 13:01:10 -06:00
|
|
|
renderRateControl(rate) {
|
2016-02-10 04:39:54 -07:00
|
|
|
const isSelected = (this.state.rate == rate);
|
2015-04-08 13:01:10 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={() => { this.setState({rate: rate}) }}>
|
|
|
|
<Text style={[styles.controlOption, {fontWeight: isSelected ? "bold" : "normal"}]}>
|
|
|
|
{rate}x
|
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
)
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
2015-04-08 13:01:10 -06:00
|
|
|
|
|
|
|
renderResizeModeControl(resizeMode) {
|
2016-02-10 04:39:54 -07:00
|
|
|
const isSelected = (this.state.resizeMode == resizeMode);
|
2015-04-08 13:01:10 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={() => { this.setState({resizeMode: resizeMode}) }}>
|
|
|
|
<Text style={[styles.controlOption, {fontWeight: isSelected ? "bold" : "normal"}]}>
|
|
|
|
{resizeMode}
|
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
)
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
2015-04-08 13:01:10 -06:00
|
|
|
|
|
|
|
renderVolumeControl(volume) {
|
2016-02-10 04:39:54 -07:00
|
|
|
const isSelected = (this.state.volume == volume);
|
2015-04-08 13:01:10 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={() => { this.setState({volume: volume}) }}>
|
|
|
|
<Text style={[styles.controlOption, {fontWeight: isSelected ? "bold" : "normal"}]}>
|
|
|
|
{volume * 100}%
|
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
)
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
2015-04-08 13:01:10 -06:00
|
|
|
|
2017-04-20 12:10:06 -06:00
|
|
|
renderIgnoreSilentSwitchControl(ignoreSilentSwitch) {
|
|
|
|
const isSelected = (this.state.ignoreSilentSwitch == ignoreSilentSwitch);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={() => { this.setState({ignoreSilentSwitch: ignoreSilentSwitch}) }}>
|
|
|
|
<Text style={[styles.controlOption, {fontWeight: isSelected ? "bold" : "normal"}]}>
|
|
|
|
{ignoreSilentSwitch}
|
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2015-12-22 16:39:04 -07:00
|
|
|
renderCustomSkin() {
|
2016-02-10 04:39:54 -07:00
|
|
|
const flexCompleted = this.getCurrentTimePercentage() * 100;
|
|
|
|
const flexRemaining = (1 - this.getCurrentTimePercentage()) * 100;
|
2015-04-08 13:01:10 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2015-08-25 00:03:55 -06:00
|
|
|
<TouchableOpacity style={styles.fullScreen} onPress={() => {this.setState({paused: !this.state.paused})}}>
|
2016-04-12 12:31:05 -06:00
|
|
|
<Video
|
2017-01-31 05:49:23 -07:00
|
|
|
source={require('./broadchurch.mp4')}
|
2016-04-12 12:31:05 -06:00
|
|
|
style={styles.fullScreen}
|
|
|
|
rate={this.state.rate}
|
|
|
|
paused={this.state.paused}
|
|
|
|
volume={this.state.volume}
|
|
|
|
muted={this.state.muted}
|
2017-04-20 12:10:06 -06:00
|
|
|
ignoreSilentSwitch={this.state.ignoreSilentSwitch}
|
2016-04-12 12:31:05 -06:00
|
|
|
resizeMode={this.state.resizeMode}
|
|
|
|
onLoad={this.onLoad}
|
2017-01-11 05:51:45 -07:00
|
|
|
onBuffer={this.onBuffer}
|
2016-04-12 12:31:05 -06:00
|
|
|
onProgress={this.onProgress}
|
|
|
|
onEnd={() => { AlertIOS.alert('Done!') }}
|
|
|
|
repeat={true}
|
2018-12-13 20:30:38 -07:00
|
|
|
filter={this.state.filter}
|
|
|
|
filterEnabled={this.state.filterEnabled}
|
2016-04-12 12:31:05 -06:00
|
|
|
/>
|
2015-04-08 13:01:10 -06:00
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
|
|
<View style={styles.controls}>
|
2015-12-22 16:39:04 -07:00
|
|
|
<View style={styles.generalControls}>
|
|
|
|
<View style={styles.skinControl}>
|
|
|
|
{this.renderSkinControl('custom')}
|
|
|
|
{this.renderSkinControl('native')}
|
|
|
|
{this.renderSkinControl('embed')}
|
|
|
|
</View>
|
2018-12-13 20:30:38 -07:00
|
|
|
{
|
|
|
|
(this.state.filterEnabled) ?
|
|
|
|
<View style={styles.skinControl}>
|
|
|
|
<TouchableOpacity onPress={() => {
|
|
|
|
this.setFilter(-1)
|
|
|
|
}}>
|
|
|
|
<Text style={styles.controlOption}>Previous Filter</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity onPress={() => {
|
|
|
|
this.setFilter(1)
|
|
|
|
}}>
|
|
|
|
<Text style={styles.controlOption}>Next Filter</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View> : null
|
|
|
|
}
|
2015-12-22 16:39:04 -07:00
|
|
|
</View>
|
2015-04-08 13:01:10 -06:00
|
|
|
<View style={styles.generalControls}>
|
|
|
|
<View style={styles.rateControl}>
|
|
|
|
{this.renderRateControl(0.5)}
|
|
|
|
{this.renderRateControl(1.0)}
|
|
|
|
{this.renderRateControl(2.0)}
|
|
|
|
</View>
|
|
|
|
|
|
|
|
<View style={styles.volumeControl}>
|
|
|
|
{this.renderVolumeControl(0.5)}
|
|
|
|
{this.renderVolumeControl(1)}
|
|
|
|
{this.renderVolumeControl(1.5)}
|
|
|
|
</View>
|
|
|
|
|
|
|
|
<View style={styles.resizeModeControl}>
|
|
|
|
{this.renderResizeModeControl('cover')}
|
|
|
|
{this.renderResizeModeControl('contain')}
|
|
|
|
{this.renderResizeModeControl('stretch')}
|
|
|
|
</View>
|
|
|
|
</View>
|
2017-04-20 12:10:06 -06:00
|
|
|
<View style={styles.generalControls}>
|
|
|
|
{
|
|
|
|
(Platform.OS === 'ios') ?
|
|
|
|
<View style={styles.ignoreSilentSwitchControl}>
|
|
|
|
{this.renderIgnoreSilentSwitchControl('ignore')}
|
|
|
|
{this.renderIgnoreSilentSwitchControl('obey')}
|
|
|
|
</View> : null
|
|
|
|
}
|
|
|
|
</View>
|
2015-04-08 13:01:10 -06:00
|
|
|
|
|
|
|
<View style={styles.trackingControls}>
|
|
|
|
<View style={styles.progress}>
|
|
|
|
<View style={[styles.innerProgressCompleted, {flex: flexCompleted}]} />
|
|
|
|
<View style={[styles.innerProgressRemaining, {flex: flexRemaining}]} />
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
2015-12-22 16:39:04 -07:00
|
|
|
|
|
|
|
renderNativeSkin() {
|
2016-02-10 04:39:54 -07:00
|
|
|
const videoStyle = this.state.skin == 'embed' ? styles.nativeVideoControls : styles.fullScreen;
|
2015-12-22 16:39:04 -07:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.fullScreen}>
|
2016-04-12 12:31:05 -06:00
|
|
|
<Video
|
2017-01-31 05:49:23 -07:00
|
|
|
source={require('./broadchurch.mp4')}
|
2016-04-12 12:31:05 -06:00
|
|
|
style={videoStyle}
|
|
|
|
rate={this.state.rate}
|
|
|
|
paused={this.state.paused}
|
|
|
|
volume={this.state.volume}
|
|
|
|
muted={this.state.muted}
|
2017-04-20 12:10:06 -06:00
|
|
|
ignoreSilentSwitch={this.state.ignoreSilentSwitch}
|
2016-04-12 12:31:05 -06:00
|
|
|
resizeMode={this.state.resizeMode}
|
|
|
|
onLoad={this.onLoad}
|
2017-01-11 05:51:45 -07:00
|
|
|
onBuffer={this.onBuffer}
|
2016-04-12 12:31:05 -06:00
|
|
|
onProgress={this.onProgress}
|
|
|
|
onEnd={() => { AlertIOS.alert('Done!') }}
|
|
|
|
repeat={true}
|
|
|
|
controls={this.state.controls}
|
2018-12-13 20:30:38 -07:00
|
|
|
filter={this.state.filter}
|
|
|
|
filterEnabled={this.state.filterEnabled}
|
2019-12-09 21:40:49 -07:00
|
|
|
adTagUrl={adTagUrl}
|
2016-04-12 12:31:05 -06:00
|
|
|
/>
|
2015-12-22 16:39:04 -07:00
|
|
|
</View>
|
|
|
|
<View style={styles.controls}>
|
|
|
|
<View style={styles.generalControls}>
|
|
|
|
<View style={styles.skinControl}>
|
|
|
|
{this.renderSkinControl('custom')}
|
|
|
|
{this.renderSkinControl('native')}
|
|
|
|
{this.renderSkinControl('embed')}
|
|
|
|
</View>
|
2018-12-13 20:30:38 -07:00
|
|
|
{
|
|
|
|
(this.state.filterEnabled) ?
|
|
|
|
<View style={styles.skinControl}>
|
|
|
|
<TouchableOpacity onPress={() => {
|
|
|
|
this.setFilter(-1)
|
|
|
|
}}>
|
|
|
|
<Text style={styles.controlOption}>Previous Filter</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity onPress={() => {
|
|
|
|
this.setFilter(1)
|
|
|
|
}}>
|
|
|
|
<Text style={styles.controlOption}>Next Filter</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View> : null
|
|
|
|
}
|
2015-12-22 16:39:04 -07:00
|
|
|
</View>
|
|
|
|
<View style={styles.generalControls}>
|
|
|
|
<View style={styles.rateControl}>
|
|
|
|
{this.renderRateControl(0.5)}
|
|
|
|
{this.renderRateControl(1.0)}
|
|
|
|
{this.renderRateControl(2.0)}
|
|
|
|
</View>
|
|
|
|
|
|
|
|
<View style={styles.volumeControl}>
|
|
|
|
{this.renderVolumeControl(0.5)}
|
|
|
|
{this.renderVolumeControl(1)}
|
|
|
|
{this.renderVolumeControl(1.5)}
|
|
|
|
</View>
|
|
|
|
|
|
|
|
<View style={styles.resizeModeControl}>
|
|
|
|
{this.renderResizeModeControl('cover')}
|
|
|
|
{this.renderResizeModeControl('contain')}
|
|
|
|
{this.renderResizeModeControl('stretch')}
|
|
|
|
</View>
|
|
|
|
</View>
|
2017-04-20 12:10:06 -06:00
|
|
|
<View style={styles.generalControls}>
|
|
|
|
{
|
|
|
|
(Platform.OS === 'ios') ?
|
|
|
|
<View style={styles.ignoreSilentSwitchControl}>
|
|
|
|
{this.renderIgnoreSilentSwitchControl('ignore')}
|
|
|
|
{this.renderIgnoreSilentSwitchControl('obey')}
|
|
|
|
</View> : null
|
|
|
|
}
|
|
|
|
</View>
|
2015-12-22 16:39:04 -07:00
|
|
|
</View>
|
|
|
|
|
|
|
|
</View>
|
|
|
|
);
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
|
|
|
|
2015-12-22 16:39:04 -07:00
|
|
|
render() {
|
|
|
|
return this.state.controls ? this.renderNativeSkin() : this.renderCustomSkin();
|
2015-04-08 13:01:10 -06:00
|
|
|
}
|
2016-02-10 04:39:54 -07:00
|
|
|
}
|
2015-04-08 13:01:10 -06:00
|
|
|
|
2016-02-10 04:39:54 -07:00
|
|
|
const styles = StyleSheet.create({
|
2015-04-08 13:01:10 -06:00
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
backgroundColor: 'black',
|
|
|
|
},
|
2015-08-25 00:03:55 -06:00
|
|
|
fullScreen: {
|
2015-04-08 13:01:10 -06:00
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
},
|
|
|
|
controls: {
|
|
|
|
backgroundColor: "transparent",
|
|
|
|
borderRadius: 5,
|
|
|
|
position: 'absolute',
|
2015-12-22 16:39:04 -07:00
|
|
|
bottom: 44,
|
|
|
|
left: 4,
|
|
|
|
right: 4,
|
2015-04-08 13:01:10 -06:00
|
|
|
},
|
|
|
|
progress: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
borderRadius: 3,
|
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
innerProgressCompleted: {
|
|
|
|
height: 20,
|
|
|
|
backgroundColor: '#cccccc',
|
|
|
|
},
|
|
|
|
innerProgressRemaining: {
|
|
|
|
height: 20,
|
|
|
|
backgroundColor: '#2C2C2C',
|
|
|
|
},
|
|
|
|
generalControls: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
overflow: 'hidden',
|
|
|
|
paddingBottom: 10,
|
|
|
|
},
|
2015-12-22 16:39:04 -07:00
|
|
|
skinControl: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
2015-04-08 13:01:10 -06:00
|
|
|
rateControl: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
volumeControl: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
resizeModeControl: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
2015-12-22 16:39:04 -07:00
|
|
|
justifyContent: 'center'
|
2015-04-08 13:01:10 -06:00
|
|
|
},
|
2017-04-20 12:10:06 -06:00
|
|
|
ignoreSilentSwitchControl: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
2015-04-08 13:01:10 -06:00
|
|
|
controlOption: {
|
|
|
|
alignSelf: 'center',
|
|
|
|
fontSize: 11,
|
|
|
|
color: "white",
|
|
|
|
paddingLeft: 2,
|
|
|
|
paddingRight: 2,
|
|
|
|
lineHeight: 12,
|
|
|
|
},
|
2015-12-22 16:39:04 -07:00
|
|
|
nativeVideoControls: {
|
|
|
|
top: 184,
|
|
|
|
height: 300
|
|
|
|
}
|
2015-04-08 13:01:10 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
AppRegistry.registerComponent('VideoPlayer', () => VideoPlayer);
|