/** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; var React = require('react-native'); var { AppRegistry, StyleSheet, Text, View, TouchableOpacity, } = React; var Video = require('react-native-video'); var VideoPlayer = React.createClass({ getInitialState() { return { rate: 1, volume: 1, muted: false, resizeMode: 'contain', // cover, stretch duration: 0.0, currentTime: 0.0, } }, onLoad(data) { this.setState({duration: data.duration}); }, onProgress(data) { this.setState({currentTime: data.currentTime}); }, getCurrentTimePercentage() { if (this.state.currentTime > 0) { return parseFloat(this.state.currentTime) / parseFloat(this.state.duration); } else { return 0; } }, renderRateControl(rate) { var isSelected = (this.state.rate == rate); return ( { this.setState({rate: rate}) }}> {rate}x ) }, renderResizeModeControl(resizeMode) { var isSelected = (this.state.resizeMode == resizeMode); return ( { this.setState({resizeMode: resizeMode}) }}> {resizeMode} ) }, renderVolumeControl(volume) { var isSelected = (this.state.volume == volume); return ( { this.setState({volume: volume}) }}> {volume * 100}% ) }, render() { var flexCompleted = this.getCurrentTimePercentage() * 100; var flexRemaining = (1 - this.getCurrentTimePercentage()) * 100; return ( {this.setState({paused: !this.state.paused})}}> {this.renderRateControl(0.25)} {this.renderRateControl(0.5)} {this.renderRateControl(1.0)} {this.renderRateControl(1.5)} {this.renderRateControl(2.0)} {this.renderVolumeControl(0.5)} {this.renderVolumeControl(1)} {this.renderVolumeControl(1.5)} {this.renderResizeModeControl('cover')} {this.renderResizeModeControl('contain')} {this.renderResizeModeControl('stretch')} ); } }); var styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'black', }, video: { position: 'absolute', top: 0, left: 0, bottom: 0, right: 0, }, controls: { backgroundColor: "transparent", borderRadius: 5, position: 'absolute', bottom: 20, left: 20, right: 20, }, progress: { flex: 1, flexDirection: 'row', borderRadius: 3, overflow: 'hidden', }, innerProgressCompleted: { height: 20, backgroundColor: '#cccccc', }, innerProgressRemaining: { height: 20, backgroundColor: '#2C2C2C', }, generalControls: { flex: 1, flexDirection: 'row', borderRadius: 4, overflow: 'hidden', paddingBottom: 10, }, rateControl: { flex: 1, flexDirection: 'row', justifyContent: 'center', }, volumeControl: { flex: 1, flexDirection: 'row', justifyContent: 'center', }, resizeModeControl: { flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', }, controlOption: { alignSelf: 'center', fontSize: 11, color: "white", paddingLeft: 2, paddingRight: 2, lineHeight: 12, }, }); AppRegistry.registerComponent('VideoPlayer', () => VideoPlayer);