2018-02-28 05:56:43 -07:00
|
|
|
/**
|
|
|
|
* Sample React Native App
|
|
|
|
* https://github.com/facebook/react-native
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React, { Component } from "react";
|
2019-01-24 05:15:58 -07:00
|
|
|
import { Alert, StyleSheet, Text, View, Dimensions, TouchableOpacity } from "react-native";
|
2018-03-01 15:51:30 -07:00
|
|
|
import Video from "react-native-video";
|
|
|
|
|
|
|
|
const { height, width } = Dimensions.get("screen");
|
2018-02-28 05:56:43 -07:00
|
|
|
|
|
|
|
type Props = {};
|
2019-01-24 05:15:58 -07:00
|
|
|
|
|
|
|
type State = {
|
|
|
|
showLocal: boolean
|
|
|
|
};
|
|
|
|
|
|
|
|
function Button({ text, onPress }: { text: string, onPress: () => void }) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
onPress={onPress}
|
|
|
|
style={styles.button}
|
|
|
|
>
|
|
|
|
<Text style={{color: 'white'}}>{text}</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class App extends Component<Props, State> {
|
|
|
|
state = {
|
|
|
|
showLocal: false
|
|
|
|
}
|
2018-02-28 05:56:43 -07:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2018-03-01 15:51:30 -07:00
|
|
|
<Video
|
2019-01-24 05:15:58 -07:00
|
|
|
source={
|
|
|
|
this.state.showLocal ?
|
|
|
|
require('../basic/broadchurch.mp4') :
|
|
|
|
{
|
|
|
|
uri: "https://rawgit.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4"
|
|
|
|
}
|
|
|
|
}
|
2018-03-01 15:51:30 -07:00
|
|
|
ref={player => {
|
|
|
|
this.player = player;
|
|
|
|
}}
|
|
|
|
onEnd={() => {
|
|
|
|
this.player.seek(0);
|
|
|
|
}}
|
2019-01-24 05:15:58 -07:00
|
|
|
onError={(err) => {
|
|
|
|
Alert.alert(JSON.stringify(err))
|
|
|
|
}}
|
2018-03-01 15:51:30 -07:00
|
|
|
style={{ flex: 1, height, width }}
|
|
|
|
/>
|
2019-01-24 05:15:58 -07:00
|
|
|
<View style={styles.absoluteOverlay}>
|
|
|
|
<Button
|
|
|
|
onPress={async () => {
|
|
|
|
let response = await this.player.save();
|
|
|
|
let uri = response.uri;
|
|
|
|
console.warn("Download URI", uri);
|
|
|
|
}}
|
|
|
|
text="Save"
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
onPress={() => {
|
|
|
|
this.setState(state => ({ showLocal: !state.showLocal }))
|
|
|
|
}}
|
|
|
|
text={this.state.showLocal ? "Show Remote" : "Show Local"}
|
|
|
|
/>
|
|
|
|
</View>
|
2018-02-28 05:56:43 -07:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: "center",
|
|
|
|
alignItems: "center",
|
|
|
|
backgroundColor: "#F5FCFF"
|
|
|
|
},
|
2019-01-24 05:15:58 -07:00
|
|
|
absoluteOverlay: {
|
|
|
|
flexDirection: 'row',
|
2018-11-06 19:33:33 -07:00
|
|
|
position: 'absolute',
|
2019-01-24 05:15:58 -07:00
|
|
|
top: 0,
|
|
|
|
width: '100%',
|
|
|
|
marginTop: 50,
|
|
|
|
},
|
|
|
|
button: {
|
2018-11-06 19:33:33 -07:00
|
|
|
padding: 10,
|
|
|
|
backgroundColor: '#9B2FAE',
|
2019-01-24 05:15:58 -07:00
|
|
|
borderRadius: 8,
|
|
|
|
flex: 1,
|
|
|
|
alignItems: 'center',
|
|
|
|
marginHorizontal: 5,
|
2018-11-06 19:33:33 -07:00
|
|
|
},
|
2018-02-28 05:56:43 -07:00
|
|
|
welcome: {
|
|
|
|
fontSize: 20,
|
|
|
|
textAlign: "center",
|
|
|
|
margin: 10
|
|
|
|
}
|
|
|
|
});
|