forked from THEOplayer/react-native-theoplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
157 lines (147 loc) · 5.49 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
import * as React from 'react';
import { useState } from 'react';
import {
AirplayButton,
CastMessage,
CenteredControlBar,
CenteredDelayedActivityIndicator,
ChromecastButton,
ControlBar,
DEFAULT_THEOPLAYER_THEME,
FullscreenButton,
LanguageMenuButton,
MuteButton,
PipButton,
PlaybackRateSubMenu,
PlayButton,
QualitySubMenu,
SeekBar,
SettingsMenuButton,
SkipButton,
Spacer,
TimeLabel,
UiContainer,
} from '@theoplayer/react-native-ui';
import {
CastLabsFairplayContentProtectionIntegrationFactory,
CastLabsWidevineContentProtectionIntegrationFactory,
CastLabsPlayReadyContentProtectionIntegrationFactory,
} from "@theoplayer/react-native-drm"
import { PlayerConfiguration, PlayerEventType, THEOplayer, THEOplayerView, ContentProtectionRegistry } from 'react-native-theoplayer';
import { Platform, StyleSheet, View, ViewStyle } from 'react-native';
import { SourceMenuButton, SOURCES } from './custom/SourceMenuButton';
import { BackgroundAudioSubMenu } from './custom/BackgroundAudioSubMenu';
import { PiPSubMenu } from './custom/PipSubMenu';
const playerConfig: PlayerConfiguration = {
// Get your THEOplayer license from https://portal.theoplayer.com/
// Without a license, only demo sources hosted on '*.theoplayer.com' domains can be played.
license: "",
chromeless: true,
libraryLocation: 'theoplayer',
mediaControl: {
mediaSessionEnabled: true,
},
};
ContentProtectionRegistry.registerContentProtectionIntegration(
"castlabs", // integrationId
"fairplay", // keySystemId
new CastLabsFairplayContentProtectionIntegrationFactory(),
)
ContentProtectionRegistry.registerContentProtectionIntegration(
"castlabs", // integrationId
"widevine", // keySystemId
new CastLabsWidevineContentProtectionIntegrationFactory(),
)
ContentProtectionRegistry.registerContentProtectionIntegration(
"castlabs", // integrationId
"playready", // keySystemId
new CastLabsPlayReadyContentProtectionIntegrationFactory(),
)
/**
* 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<THEOplayer | undefined>(undefined);
const chromeless = playerConfig?.chromeless ?? false;
const onPlayerReady = (player: THEOplayer) => {
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.source = SOURCES[0].source;
player.backgroundAudioConfiguration = { enabled: true };
player.pipConfiguration = { startsAutomatically: true };
console.log('THEOplayer is ready:', player.version);
};
const needsBorder = Platform.OS === 'ios';
const PLAYER_CONTAINER_STYLE: ViewStyle = {
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>
{/*This is a custom menu for source selection.*/}
<SourceMenuButton />
{!Platform.isTV && (
<>
<AirplayButton />
</>
)}
<LanguageMenuButton />
<SettingsMenuButton>
{/*Note: quality selection is not available on iOS */}
<QualitySubMenu />
<PlaybackRateSubMenu />
<BackgroundAudioSubMenu />
<PiPSubMenu />
</SettingsMenuButton>
</ControlBar>
}
center={<CenteredControlBar left={<SkipButton skip={-10} />} middle={<PlayButton />} right={<SkipButton skip={30} />} />}
bottom={
<>
<ControlBar style={{ justifyContent: 'flex-start' }}>
</ControlBar>
<ControlBar>
<SeekBar />
</ControlBar>
<ControlBar>
<MuteButton />
<TimeLabel showDuration={true} />
<Spacer />
<PipButton />
<FullscreenButton />
</ControlBar>
</>
}
/>
)}
</THEOplayerView>
</View>
</View>
);
}