-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
App.tsx
249 lines (235 loc) · 7.21 KB
/
App.tsx
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import * as ScreenOrientation from 'expo-screen-orientation'
import { Dimensions, ScrollView, StyleSheet, Text } from 'react-native'
import { ResizeMode } from 'expo-av'
import { setStatusBarHidden } from 'expo-status-bar'
import React, { useRef, useState } from 'react'
import VideoPlayer from 'expo-video-player'
const App = () => {
const [inFullscreen, setInFullsreen] = useState(false)
const [inFullscreen2, setInFullsreen2] = useState(false)
const [isMute, setIsMute] = useState(false)
const refVideo = useRef(null)
const refVideo2 = useRef(null)
const refScrollView = useRef(null)
return (
<ScrollView
scrollEnabled={!inFullscreen2}
ref={refScrollView}
onContentSizeChange={() => {
if (inFullscreen2) {
refScrollView.current.scrollToEnd({ animated: true })
}
}}
style={styles.container}
contentContainerStyle={styles.contentContainer}
>
<Text style={[styles.text, { fontWeight: 'bold', textTransform: 'uppercase' }]}>
Examples
</Text>
{/* ShouldPlay (autoplay) is true only in the first example */}
<Text style={styles.text}>Basic</Text>
<VideoPlayer
videoProps={{
shouldPlay: true,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
}}
/>
<Text style={styles.text}>Local file</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: require('./local.mp4'),
}}
style={{ height: 160 }}
/>
<Text style={styles.text}>Only video without controls</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
}}
slider={{
visible: false,
}}
fullscreen={{
visible: false,
}}
timeVisible={false}
style={{ height: 160 }}
/>
<Text style={styles.text}>Some styling</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
}}
style={{
videoBackgroundColor: 'transparent',
controlsBackgroundColor: 'red',
height: 200,
}}
/>
<Text style={styles.text}>With custom icons</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
}}
icon={{
play: <Text style={{ color: '#FFF' }}>PLAY</Text>,
pause: <Text style={{ color: '#FFF' }}>PAUSE</Text>,
}}
style={{ height: 160 }}
/>
<Text style={styles.text}>With some more styling</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
}}
style={{
height: 160,
width: 160,
videoBackgroundColor: 'yellow',
controlsBackgroundColor: 'blue',
}}
/>
<Text style={styles.text}>With Mute</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
isMuted: isMute,
}}
mute={{
enterMute: () => setIsMute(!isMute),
exitMute: () => setIsMute(!isMute),
isMute,
}}
style={{ height: 160 }}
/>
<Text style={styles.text}>Fullscren icon hidden</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
}}
fullscreen={{
visible: false,
}}
style={{ height: 160 }}
/>
<Text style={styles.text}>Ref - clicking on Enter/Exit fullscreen changes playing</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
ref: refVideo,
}}
fullscreen={{
enterFullscreen: () => {
setInFullsreen(!inFullscreen)
refVideo.current.setStatusAsync({
shouldPlay: true,
})
},
exitFullscreen: () => {
setInFullsreen(!inFullscreen)
refVideo.current.setStatusAsync({
shouldPlay: false,
})
},
inFullscreen,
}}
style={{ height: 160 }}
/>
<Text style={styles.text}>Fullscren</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
ref: refVideo2,
}}
fullscreen={{
inFullscreen: inFullscreen2,
enterFullscreen: async () => {
setStatusBarHidden(true, 'fade')
setInFullsreen2(!inFullscreen2)
await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_LEFT)
refVideo2.current.setStatusAsync({
shouldPlay: true,
})
},
exitFullscreen: async () => {
setStatusBarHidden(false, 'fade')
setInFullsreen2(!inFullscreen2)
await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.DEFAULT)
},
}}
style={{
videoBackgroundColor: 'black',
height: inFullscreen2 ? Dimensions.get('window').width : 160,
width: inFullscreen2 ? Dimensions.get('window').height : 320,
}}
/>
<Text style={styles.text}>Custom title</Text>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: ResizeMode.CONTAIN,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
}}
style={{
videoBackgroundColor: 'black',
}}
header={<Text style={{ color: '#FFF' }}>Custom title</Text>}
/>
</ScrollView>
)
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#FFF',
flex: 1,
},
contentContainer: {
alignItems: 'center',
justifyContent: 'center',
paddingTop: 40,
},
text: {
marginTop: 36,
marginBottom: 12,
},
})
export default App