diff --git a/documentation/src/components/Player/index.tsx b/documentation/src/components/Player/index.tsx index 71b5def0e6..fd1af54b1b 100644 --- a/documentation/src/components/Player/index.tsx +++ b/documentation/src/components/Player/index.tsx @@ -1,7 +1,8 @@ -import React, { useState, useRef } from "react"; +import React, { useState, useRef, useEffect } from "react"; import ReactPlayer from "react-player"; import { Icon } from "@iconify/react"; -import fullscreen from "screenfull"; +import screenfull from "screenfull"; +import debounce from "lodash.debounce"; interface PlayerProps { url: string; @@ -10,19 +11,40 @@ interface PlayerProps { export default function Player({ url }: PlayerProps) { const [progress, setProgress] = useState(0); const [playing, setPlaying] = useState(true); + const [isFullscreen, setIsFullscreen] = useState(false); const playerRef = useRef(null); - const playerContainerRef = useRef(null); + const playerContainerRef = useRef(null); const togglePlayPause = () => { setPlaying((prev) => !prev); }; - const handleSeek = (e: React.ChangeEvent) => { + const handleSeek = debounce((e: React.ChangeEvent) => { const newProgress = parseFloat(e.target.value); setProgress(newProgress); playerRef.current?.seekTo(newProgress / 100, "fraction"); + }, 200); + + const handleFullscreenToggle = () => { + if (screenfull.isEnabled) { + screenfull.toggle(playerContainerRef.current); + } }; + useEffect(() => { + if (screenfull.isEnabled) { + screenfull.on("change", () => { + setIsFullscreen(screenfull.isFullscreen); + }); + + return () => { + screenfull.off("change", () => { + setIsFullscreen(screenfull.isFullscreen); + }); + }; + } + }, []); + return (
@@ -32,6 +54,7 @@ export default function Player({ url }: PlayerProps) { playing={playing} loop muted + playsInline={true} controls={false} width="100%" height="100%" @@ -39,27 +62,27 @@ export default function Player({ url }: PlayerProps) { onProgress={(state) => setProgress(state.played * 100)} />
-
-
- -
-
-
- fullscreen.toggle(playerContainerRef.current)} - className="cursor-pointer hover:scale-110 transition duration-150" - icon={fullscreen.isFullscreen ? "mdi:fullscreen-exit" : "mdi:fullscreen"} - fontSize={40} - color="white" - /> -
+
+
+ +
+
+
+ +
); @@ -95,12 +118,16 @@ function Bar({ progress, onSeek }: BarProps) { value={progress} onChange={onSeek} className="absolute top-0 left-0 w-full h-[5px] opacity-0 cursor-pointer" - style={{ WebkitAppearance: "none" }} + style={{ + WebkitAppearance: "none", + MozAppearance: "none", + appearance: "none", + }} />
); -} \ No newline at end of file +}