-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
152 lines (131 loc) · 4.82 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
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
// React Native Video Library to Play Video in Android and IOS
// https://aboutreact.com/react-native-video/
// import React in our code
import React, { useState, useRef } from 'react';
// import all the components we are going to use
import { SafeAreaView, StyleSheet, Text, View } from 'react-native';
//Import React Native Video to play video
import Video from 'react-native-video';
//Media Controls to control Play/Pause/Seek and full screen
import MediaControls, { PLAYER_STATES } from 'react-native-media-controls';
const App = () => {
const videoPlayer = useRef(null);
const [currentTime, setCurrentTime] = useState(0);
const [duration, setDuration] = useState(0);
const [isFullScreen, setIsFullScreen] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const [paused, setPaused] = useState(false);
const [playerState, setPlayerState] = useState(PLAYER_STATES.PLAYING);
const [screenType, setScreenType] = useState('content');
const onSeek = (seek) => {
//Handler for change in seekbar
videoPlayer.current.seek(seek);
};
const onPaused = (playerState) => {
//Handler for Video Pause
setPaused(!paused);
setPlayerState(playerState);
};
const onReplay = () => {
//Handler for Replay
setPlayerState(PLAYER_STATES.PLAYING);
videoPlayer.current.seek(0);
};
const onProgress = (data) => {
// Video Player will continue progress even if the video already ended
if (!isLoading && playerState !== PLAYER_STATES.ENDED) {
setCurrentTime(data.currentTime);
}
};
const onLoad = (data) => {
setDuration(data.duration);
setIsLoading(false);
};
const onLoadStart = (data) => {
setIsLoading(true);
alert(data);
console.log('load',data);
}
const onEnd = () => setPlayerState(PLAYER_STATES.ENDED);
const onError = (e) => console.log(e);
const exitFullScreen = () => {
alert('Exit full screen');
};
const enterFullScreen = () => { };
const onFullScreen = () => {
setIsFullScreen(isFullScreen);
if (screenType == 'content') setScreenType('cover');
else setScreenType('content');
};
const renderToolbar = () => (
<View>
<Text style={styles.toolbar}> toolbar </Text>
</View>
);
const onSeeking = (currentTime) => setCurrentTime(currentTime);
return (
<View style={{ flex: 1 }}>
<Video
onEnd={onEnd}
onLoad={onLoad}
onLoadStart={onLoadStart}
onProgress={onProgress}
onError={onError}
paused={false}
ref={videoPlayer}
resizeMode={screenType}
onFullScreen={isFullScreen}
source={{
uri:
'https://media.axprod.net/TestVectors/Cmaf/protected_1080p_h264_cbcs/manifest.m3u8'
}}
drm={{
type: 'fairplay',
licenseServer:'https://drm-fairplay-licensing.axprod.net/AcquireLicense',
certificateUrl: 'https://vtb.axinom.com/FPScert/fairplay.cer',
headers: {
'X-AxDRM-Message':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJ2ZXJzaW9uIjogMSwKICAiY29tX2tleV9pZCI6ICI2OWU1NDA4OC1lOWUwLTQ1MzAtOGMxYS0xZWI2ZGNkMGQxNGUiLAogICJtZXNzYWdlIjogewogICAgInR5cGUiOiAiZW50aXRsZW1lbnRfbWVzc2FnZSIsCiAgICAidmVyc2lvbiI6IDIsCiAgICAibGljZW5zZSI6IHsKICAgICAgImFsbG93X3BlcnNpc3RlbmNlIjogdHJ1ZQogICAgfSwKICAgICJjb250ZW50X2tleXNfc291cmNlIjogewogICAgICAiaW5saW5lIjogWwogICAgICAgIHsKICAgICAgICAgICJpZCI6ICIzMDJmODBkZC00MTFlLTQ4ODYtYmNhNS1iYjFmODAxOGEwMjQiLAogICAgICAgICAgImVuY3J5cHRlZF9rZXkiOiAicm9LQWcwdDdKaTFpNDNmd3YremZ0UT09IiwKICAgICAgICAgICJ1c2FnZV9wb2xpY3kiOiAiUG9saWN5IEEiCiAgICAgICAgfQogICAgICBdCiAgICB9LAogICAgImNvbnRlbnRfa2V5X3VzYWdlX3BvbGljaWVzIjogWwogICAgICB7CiAgICAgICAgIm5hbWUiOiAiUG9saWN5IEEiLAogICAgICAgICJwbGF5cmVhZHkiOiB7CiAgICAgICAgICAibWluX2RldmljZV9zZWN1cml0eV9sZXZlbCI6IDE1MCwKICAgICAgICAgICJwbGF5X2VuYWJsZXJzIjogWwogICAgICAgICAgICAiNzg2NjI3RDgtQzJBNi00NEJFLThGODgtMDhBRTI1NUIwMUE3IgogICAgICAgICAgXQogICAgICAgIH0KICAgICAgfQogICAgXQogIH0KfQ._NfhLVY7S6k8TJDWPeMPhUawhympnrk6WAZHOVjER6M',
'Content-Type': 'application/octet-stream'
}
}}
style={styles.mediaPlayer}
volume={10}
controls={true}
/>
<MediaControls
duration={duration}
isLoading={isLoading}
mainColor="#333"
onFullScreen={onFullScreen}
onPaused={onPaused}
onReplay={onReplay}
onSeek={onSeek}
onSeeking={onSeeking}
playerState={playerState}
progress={currentTime}
toolbar={renderToolbar()}
/>
</View>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
},
toolbar: {
marginTop: 30,
backgroundColor: 'white',
padding: 10,
borderRadius: 5,
},
mediaPlayer: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
backgroundColor: 'black',
justifyContent: 'center',
},
});