2023-01-23 22:38:05 +01:00
|
|
|
import { Icon, Icons } from "@/components/Icon";
|
|
|
|
import { VideoPlayerIconButton } from "../parts/VideoPlayerIconButton";
|
2023-01-08 21:18:45 +01:00
|
|
|
import { useVideoPlayerState } from "../VideoContext";
|
|
|
|
|
|
|
|
function durationExceedsHour(secs: number): boolean {
|
|
|
|
return secs > 60 * 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatSeconds(secs: number, showHours = false): string {
|
2023-01-10 19:53:55 +01:00
|
|
|
if (Number.isNaN(secs)) {
|
|
|
|
if (showHours) return "0:00:00";
|
|
|
|
return "0:00";
|
|
|
|
}
|
|
|
|
|
2023-01-08 21:18:45 +01:00
|
|
|
let time = secs;
|
2023-01-17 19:11:10 +01:00
|
|
|
const seconds = Math.floor(time % 60);
|
2023-01-08 21:18:45 +01:00
|
|
|
|
2023-01-17 19:11:10 +01:00
|
|
|
time /= 60;
|
|
|
|
const minutes = Math.floor(time % 60);
|
2023-01-08 21:18:45 +01:00
|
|
|
|
2023-01-17 19:11:10 +01:00
|
|
|
time /= 60;
|
|
|
|
const hours = Math.floor(time);
|
2023-01-08 21:18:45 +01:00
|
|
|
|
2023-01-17 13:42:15 +01:00
|
|
|
const paddedSecs = seconds.toString().padStart(2, "0");
|
|
|
|
const paddedMins = minutes.toString().padStart(2, "0");
|
|
|
|
|
|
|
|
if (!showHours) return [minutes, paddedSecs].join(":");
|
|
|
|
return [hours, paddedMins, paddedSecs].join(":");
|
2023-01-08 21:18:45 +01:00
|
|
|
}
|
|
|
|
|
2023-01-09 21:51:24 +01:00
|
|
|
interface Props {
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function TimeControl(props: Props) {
|
2023-01-08 21:18:45 +01:00
|
|
|
const { videoState } = useVideoPlayerState();
|
2023-01-23 22:38:05 +01:00
|
|
|
|
|
|
|
const skipForward = () => {
|
|
|
|
videoState.setTime(videoState.time + 10);
|
|
|
|
};
|
|
|
|
|
|
|
|
const skipBackward = () => {
|
|
|
|
videoState.setTime(videoState.time - 10);
|
|
|
|
};
|
2023-01-08 21:18:45 +01:00
|
|
|
|
|
|
|
return (
|
2023-01-09 21:51:24 +01:00
|
|
|
<div className={props.className}>
|
2023-01-23 22:38:05 +01:00
|
|
|
<p className="flex select-none items-center text-white">
|
|
|
|
<VideoPlayerIconButton
|
|
|
|
icon={Icons.SKIP_BACKWARD}
|
|
|
|
onClick={skipBackward}
|
|
|
|
/>
|
|
|
|
<VideoPlayerIconButton
|
|
|
|
icon={Icons.SKIP_FORWARD}
|
|
|
|
onClick={skipForward}
|
|
|
|
/>
|
2023-01-09 21:51:24 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
2023-01-08 21:18:45 +01:00
|
|
|
);
|
|
|
|
}
|