-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
131 lines (125 loc) · 5.25 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
import * as React from 'react';
import { useState } from 'react';
import {
CenteredControlBar,
CenteredDelayedActivityIndicator,
ControlBar,
DEFAULT_THEOPLAYER_THEME,
FullscreenButton,
LanguageMenuButton,
MuteButton,
PipButton,
PlaybackRateSubMenu,
PlayButton,
QualitySubMenu,
SeekBar,
SettingsMenuButton,
SkipButton,
Spacer,
TimeLabel,
UiContainer,
} from '@theoplayer/react-native-ui';
import { PlayerEventType, THEOplayerView } from 'react-native-theoplayer';
import { Platform, StyleSheet, View } from 'react-native';
const playerConfig = {
// Get your THEOplayer license from https://portal.theoplayer.com/
// Without a license, only demo sources hosted on '*.theoplayer.com' domains can be played.
license: undefined,
chromeless: true,
hlsDateRange: true,
libraryLocation: 'theoplayer',
mediaControl: {
mediaSessionEnabled: true,
},
};
/**
* The example app demonstrates the use of the THEOplayerView with a custom UI using the provided UI components.
* If you don't want to create a custom UI, you can just use the THEOplayerDefaultUi component instead.
*/
export default function App() {
const [player, setPlayer] = useState();
const chromeless = playerConfig?.chromeless ?? false;
const onPlayerReady = (player) => {
setPlayer(player);
// optional debug logs
player.addEventListener(PlayerEventType.SOURCE_CHANGE, console.log);
player.addEventListener(PlayerEventType.LOADED_DATA, console.log);
player.addEventListener(PlayerEventType.LOADED_METADATA, console.log);
player.addEventListener(PlayerEventType.READYSTATE_CHANGE, console.log);
player.addEventListener(PlayerEventType.PLAY, console.log);
player.addEventListener(PlayerEventType.PLAYING, console.log);
player.addEventListener(PlayerEventType.PAUSE, console.log);
player.addEventListener(PlayerEventType.SEEKING, console.log);
player.addEventListener(PlayerEventType.SEEKED, console.log);
player.addEventListener(PlayerEventType.ENDED, console.log);
player.addEventListener(PlayerEventType.ERROR, console.log);
player.source = {
"sources": [{
"src": "https://cdn.theoplayer.com/video/big_buck_bunny/big_buck_bunny.m3u8",
"type": "application/x-mpegurl"
}],
"poster": "https://cdn.theoplayer.com/video/big_buck_bunny/poster.jpg",
"metadata": {
"title": "The Title",
"subtitle": "The Subtitle",
"album": "Album",
"displayIconUri": "https://cdn.theoplayer.com/video/big_buck_bunny/poster.jpg",
"artist": "Artist"
}
};
player.backgroundAudioConfiguration = { enabled: true };
player.pipConfiguration = { startsAutomatically: true };
console.log('THEOplayer is ready:', player.version);
};
const needsBorder = Platform.OS === 'ios';
const PLAYER_CONTAINER_STYLE = {
position: 'absolute',
top: needsBorder ? 20 : 0,
left: needsBorder ? 5 : 0,
bottom: 0,
right: needsBorder ? 5 : 0,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#000000',
};
return (
<View style={[StyleSheet.absoluteFill, { backgroundColor: '#000000' }]}>
<View style={PLAYER_CONTAINER_STYLE}>
<THEOplayerView config={playerConfig} onPlayerReady={onPlayerReady}>
{player !== undefined && chromeless && (
<UiContainer
theme={{ ...DEFAULT_THEOPLAYER_THEME }}
player={player}
behind={<CenteredDelayedActivityIndicator size={50} />}
top={
<ControlBar>
<LanguageMenuButton />
<SettingsMenuButton>
{/*Note: quality selection is not available on iOS */}
<QualitySubMenu />
<PlaybackRateSubMenu />
</SettingsMenuButton>
</ControlBar>
}
center={<CenteredControlBar left={<SkipButton skip={-10} />} middle={<PlayButton />} right={<SkipButton skip={30} />} />}
bottom={
<>
<ControlBar>
<SeekBar />
</ControlBar>
<ControlBar>
<MuteButton />
<TimeLabel showDuration={true} />
<Spacer />
<PipButton />
<FullscreenButton />
</ControlBar>
</>
}
/>
)}
</THEOplayerView>
</View>
</View>
);
}