-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
46 lines (39 loc) · 1.32 KB
/
App.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
import { useVideoPlayer, VideoView } from 'expo-video';
import { useEffect, useState } from 'react';
import { View, Button, Text } from 'react-native';
const videoSource =
'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4';
export default function App() {
const player = useVideoPlayer(videoSource, (player1) => {
player1.muted = true;
player1.loop = true;
player1.play();
});
const [shouldVideoViewMount, setShouldVideoViewMount] = useState(false);
const [playerStatus, setPlayerStatus] = useState(undefined);
useEffect(() => {
const subscription = player.addListener('statusChange', status => {
setPlayerStatus(status)
});
return () => {
subscription.remove();
};
}, [player]);
return (
<View style={{flex: 1}}>
<View style={{ height: 400, width: 300, borderColor: 'black', borderWidth: 1}}>
{shouldVideoViewMount ?
<VideoView
player={player}
contentFit="cover"
style={{width: '100%', height: '100%'}}
nativeControls={false}
/> :
null
}
</View>
<Text>Player Status: {playerStatus}</Text>
<Button title={!shouldVideoViewMount ? 'Mount' : 'Unmount'} onPress={() => setShouldVideoViewMount(!shouldVideoViewMount)} />
</View>
);
}