-
Notifications
You must be signed in to change notification settings - Fork 54
/
PlayeriOS.js
executable file
·144 lines (126 loc) · 3.92 KB
/
PlayeriOS.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React, { Component } from 'react';
import {
AppState,
StyleSheet,
View,
Dimensions,
TouchableOpacity,
} from 'react-native';
import VLCPlayer from 'react-native-vlcplayer';
import * as Progress from 'react-native-progress';
import Icon from 'react-native-vector-icons/FontAwesome';
import { Bars } from 'react-native-loader';
import Orientation from 'react-native-orientation';
const playerDefaultHeight = Dimensions.get('window').width;
const playerDefaultWidth = Dimensions.get('window').height;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#000000',
},
vlcplayer: {
width: playerDefaultWidth,
height: playerDefaultHeight,
backgroundColor: 'black',
},
buttonBox: {
position: 'absolute',
top: -(playerDefaultHeight),
alignItems: 'center',
justifyContent: 'center',
width: playerDefaultWidth,
height: playerDefaultHeight,
},
});
export default class PlayeriOS extends Component {
constructor(props) {
super(props);
this.state = {
appState: AppState.currentState,
progress: 0,
paused: true,
playButtonColor: 'rgba(255,255,255,1)',
loadingColor: 'rgba(255,255,255,0)',
buttonSize: 70,
progressWidth: playerDefaultWidth,
};
if (this.props.buttonSize) {
this.state.buttonSize = this.props.buttonSize;
}
}
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
Orientation.lockToPortrait();
Orientation.unlockAllOrientations();
}
_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
// console.log('App has come to the foreground!')
} else {
const { goBack } = this.props.navigation;
goBack();
}
this.setState({ appState: nextAppState });
}
render() {
const defaultControlsView = this.defaultControlsView();
return (
<View style={styles.container}>
<VLCPlayer
ref='vlcplayer'
onBuffering={this.onBuffering.bind(this)}
onEnded={this.onEnded.bind(this)}
onPaused={this.onPaused.bind(this)}
onPlaying={this.onPlaying.bind(this)}
onProgress={this.onProgress.bind(this)}
onStopped={this.onEnded.bind(this)}
paused={this.state.paused}
source={{ uri: this.props.navigation.state.params.uri, initOptions: ['--codec=avcodec'] }}
style={[styles.vlcplayer]} />
{defaultControlsView}
</View>
);
}
pause() {
if (!this.state.paused) { return; }
Orientation.lockToLandscape();
this.setState({ paused: !this.state.paused });
}
onPlaying(event) {
this.setState({ loadingColor: 'rgba(255,255,255,0)' });
this.setState({ playButtonColor: 'rgba(255,255,255,0)' });
}
onPaused(event) {
this.setState({ loadingColor: 'rgba(255,255,255,0)' });
this.setState({ playButtonColor: 'rgba(255,255,255,1)' });
}
onBuffering(event) {
this.setState({ playButtonColor: 'rgba(255,255,255,0)' });
this.setState({ loadingColor: 'rgba(255,255,255,1)' });
}
defaultControlsView() {
return (
<View>
<View style={[styles.buttonBox, { backgroundColor: 'rgba(0,0,0,0)' }]}>
<Bars color={this.state.loadingColor} size={10} />
</View>
<TouchableOpacity activeOpacity={1} onPress={this.pause.bind(this)} style={[styles.buttonBox]}>
<Icon.Button backgroundColor='rgba(0,0,0,0)' color={this.state.playButtonColor} name='play-circle-o' onPress={this.pause.bind(this)} size={this.state.buttonSize} />
</TouchableOpacity>
<Progress.Bar ref='progress' borderRadius={0} borderWidth={0} color='rgba(255,0,0,1)' height={3} progress={this.state.progress} width={this.state.progressWidth} />
</View>
);
}
onProgress(event) {
this.setState({ progress: event.position });
this.setState({ loadingColor: 'rgba(255,255,255,0)' });
}
onEnded(event) {
this.setState({ progress: 1 });
this.setState({ playButtonColor: 'rgba(255,255,255,1)' });
}
}