-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathApp.tsx
111 lines (101 loc) · 3.32 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
import { useEffect } from "react";
import { TVPlayer, useTVPlayerStore, TVPlayerButtonProps } from "./lib";
import { faGithub } from "@fortawesome/free-brands-svg-icons";
import "./App.css";
// locally testing built library
//import { TVPlayer, useTVPlayerStore, TVPlayerButtonProps } from "./..";
export type MediaType = {
url: string | string[] | MediaStream;
title?: string;
subTitle?: string;
preview?: string | boolean;
};
const mediaList: MediaType[] = [
{
url: "https://www.youtube.com/watch?v=SkVqJ1SGeL0",
title: "YouTube Video Sample",
subTitle: "Caminandes 3: Llamigos",
preview: true,
},
{
url: "https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8",
title: "HLS Stream Sample",
subTitle: "Tears of Steel",
preview:
"https://mango.blender.org/wp-content/gallery/4k-renders/06_barley.jpg",
},
{
title: "Dash Stream Sample",
subTitle: "Elephants Dream",
url: "https://rdmedia.bbc.co.uk/elephants_dream/1/client_manifest-all.mpd",
preview:
"https://orange.blender.org/wp-content/themes/orange/images/media/gallery/s1_proog.jpg",
},
];
function App() {
const actions = useTVPlayerStore((s) => s.actions);
const mediaIndex = useTVPlayerStore((s) => s.mediaIndex) || 0;
const likeToggle = useTVPlayerStore((s) => s.likeToggle);
const fullscreen = useTVPlayerStore((s) => s.fullscreen);
const customButtons: TVPlayerButtonProps[] = [
{ action: "loop", align: "left" },
{ action: "like", align: "left" },
{ action: "previous", align: "center" },
{ action: "playpause", align: "center" },
{ action: "next", align: "center" },
{ action: "fullscreen", align: "right" },
{
action: "custom",
align: "right",
label: "About",
faIcon: faGithub,
onPress: () => {
window.location.href = "https://github.com/lewhunt/react-tv-player";
},
},
];
const handleLike = () => {
console.log("like button pressed");
// custom app logic for like
actions.setLikeToggle(!likeToggle);
};
// Called when an error occurs whilst attempting to play media
const handleError = (
error: any,
data: any,
hlsInstance: any,
hlsGlobal: any
) => {
console.log("error: ", error);
console.log("data (optional): ", data);
console.log("hlsInstance (optional): ", hlsInstance);
console.log("hlsGlobal (optional): ", hlsGlobal);
};
// example of toggling global CSS stylings based on fullscreen state
useEffect(() => {
document.body.style.background = fullscreen ? "black" : "unset";
document.body.style.overflow = fullscreen ? "hidden" : "unset";
document.body.style.padding = fullscreen ? "0" : "revert";
document.body.style.margin = fullscreen ? "0" : "revert";
}, [fullscreen]);
return (
<>
<TVPlayer
title={mediaList[mediaIndex].title}
subTitle={mediaList[mediaIndex].subTitle}
url={mediaList[mediaIndex].url}
light={mediaList[mediaIndex].preview}
customButtons={customButtons}
mediaCount={mediaList.length}
mediaIndex={0}
onLikePress={handleLike}
onError={handleError}
playsinline={true}
hideControlsOnArrowUp={true}
disableFullscreen={false}
disableInitNav={false}
/>
</>
);
}
export default App;