-
-
Notifications
You must be signed in to change notification settings - Fork 290
Expand file tree
/
Copy pathResponsivePlayer.js
More file actions
43 lines (40 loc) · 1.36 KB
/
ResponsivePlayer.js
File metadata and controls
43 lines (40 loc) · 1.36 KB
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
import React, {Suspense, lazy} from "react";
// Lazy-load react-player so it is NOT included in the initial JS bundle.
// react-player/lazy defers loading the actual player implementation until
// the component is rendered, reducing the first-page-load JS payload.
const ReactPlayer = lazy(() => import("react-player/lazy"));
function ResponsivePlayer({url, loop, playing}) {
return (
<div
className="relative rounded-lg shadow-lg"
style={{paddingTop: "56.25%"}}
>
{/* Player ratio: 100 / (1280 / 720) */}
<Suspense
fallback={
<div
className="absolute left-0 top-0 flex h-full w-full items-center justify-center bg-gray-100 dark:bg-gray-800"
role="status"
aria-label="Loading video player"
>
<div className="h-8 w-8 animate-spin rounded-full border-2 border-gray-400 border-t-transparent dark:border-gray-500" />
<span className="ml-3 text-sm font-medium text-gray-600 dark:text-gray-300">
Loading video player...
</span>
</div>
}
>
<ReactPlayer
className="absolute left-0 top-0"
url={url}
loop={loop}
playing={playing}
width="100%"
height="100%"
controls={true}
/>
</Suspense>
</div>
);
}
export default ResponsivePlayer;