@imokhles/react-native-vlc
Version:
A `VLCPlayer` component for react-native project clone from `react-native-yz-vlcplayer`
249 lines (243 loc) • 7.1 kB
JavaScript
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TouchableOpacity
} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import Slider from 'react-native-slider';
export default class ControlBtn extends Component {
static defaultProps = {
titleGolive: 'Go live',
showLeftButton: true,
showMiddleButton: true,
showRightButton: true
}
_getTime = (data = 0) => {
let hourCourse = Math.floor(data / 3600);
let diffCourse = data % 3600;
let minCourse = Math.floor(diffCourse / 60);
let secondCourse = Math.floor(diffCourse % 60);
let courseReal = '';
if (hourCourse) {
if (hourCourse < 10) {
courseReal += '0' + hourCourse + ':';
} else {
courseReal += hourCourse + ':';
}
}
if (minCourse < 10) {
courseReal += '0' + minCourse + ':';
} else {
courseReal += minCourse + ':';
}
if (secondCourse < 10) {
courseReal += '0' + secondCourse;
} else {
courseReal += secondCourse;
}
return courseReal;
};
render() {
let {
paused,
isFull,
showSlider,
onPausedPress,
onFullPress,
onValueChange,
onSlidingComplete,
currentTime,
totalTime,
style,
titleGolive,
showLeftButton,
showMiddleButton,
showRightButton,
onReplayPress,
onGoLivePress,
showGoLive
} = this.props;
return (
<View style={[styles.controls, style]}>
<View style={styles.controlContainer}>
<TouchableOpacity style={styles.controlContent} activeOpacity={1}>
<View style={styles.controlContent2}>
<View style={styles.left}>
{
showLeftButton ? (
<TouchableOpacity
activeOpacity={1}
onPress={() => {
onReplayPress && onReplayPress();
}}
style={{ width: 50, alignItems: 'center', justifyContent: 'center' }}>
<Icon name={'replay'} size={30} color="#fff" />
</TouchableOpacity>
) : <View style={{ width: 50 }} />
}
<Text
style={{ fontSize: 11, color: '#fff' }}> </Text>
</View>
{
showMiddleButton && (
<TouchableOpacity
activeOpacity={1}
onPress={() => {
onPausedPress && onPausedPress(!paused);
}}
style={{ width: 50, alignItems: 'center', justifyContent: 'center' }}>
<Icon name={paused ? 'play' : 'pause'} size={30} color="#fff" />
</TouchableOpacity>
)
}
{showSlider && totalTime > 0 && (
<View
style={{
flex: 1,
alignItems: 'center',
flexDirection: 'row'
}}>
<View style={{ justifyContent: 'center', alignItems: 'center', height: 50, minWidth: 50, }}>
<Text style={{ fontSize: 11, color: '#fff', }}>
{this._getTime(currentTime) || 0}
</Text>
</View>
<View style={styles.progress}>
<Slider
minimumTrackTintColor="#30a935"
thumbStyle={styles.thumb}
style={{ width: '100%' }}
value={currentTime}
maximumValue={totalTime}
step={1}
onValueChange={value => {
onValueChange && onValueChange(value);
}}
onSlidingComplete={value => {
onSlidingComplete && onSlidingComplete(value);
}}
/>
</View>
<View style={{ justifyContent: 'center', alignItems: 'center', height: 50, minWidth: 50 }}>
<Text
style={{ fontSize: 11, color: '#fff' }}>
{this._getTime(totalTime) || 0}
</Text>
</View>
</View>
)}
<View style={styles.right}>
<TouchableOpacity
activeOpacity={1}
onPress={() => {
onGoLivePress && onGoLivePress();
}}>
<Text
style={{ fontSize: 11, color: '#fff' }}>{showGoLive ? titleGolive : ' '}</Text>
</TouchableOpacity>
{
showRightButton ? (
<TouchableOpacity
activeOpacity={1}
onPress={() => {
onFullPress && onFullPress(!isFull);
}}
style={{ width: 50, alignItems: 'center', justifyContent: 'center' }}>
<Icon name={isFull ? 'fullscreen-exit' : 'fullscreen'} size={30} color="#fff" />
</TouchableOpacity>
) : <View style={{ width: 50 }} />
}
</View>
</View>
</TouchableOpacity>
</View>
</View >
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
controls: {
width: '100%',
height: 50,
},
rateControl: {
flex: 0,
flexDirection: 'row',
marginTop: 10,
marginLeft: 10,
width: 120,
height: 30,
justifyContent: 'space-around',
alignItems: 'center',
borderRadius: 10,
},
controlOption: {
textAlign: 'center',
fontSize: 13,
color: '#fff',
width: 30,
},
controlContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
controlContent: {
width: '100%',
height: 50,
backgroundColor: 'rgba(255,255,255,0.6)',
},
controlContent2: {
flex: 1,
flexDirection: 'row',
backgroundColor: 'rgba(0,0,0,0.7)',
alignItems: 'center',
justifyContent: 'space-between',
},
progress: {
flex: 1,
borderRadius: 3,
alignItems: 'center',
justifyContent: 'center',
},
thumb: {
width: 6,
height: 18,
backgroundColor: '#fff',
borderRadius: 4,
},
loading: {
position: 'absolute',
left: 0,
top: 0,
zIndex: 0,
width: '100%',
height: '100%',
justifyContent: 'center',
alignItems: 'center',
},
ad: {
backgroundColor: 'rgba(255,255,255,1)',
height: 30,
paddingLeft: 10,
paddingRight: 10,
borderRadius: 20,
justifyContent: 'center',
alignItems: 'center',
},
left: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
right: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
});