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 {
|
|
|
|
let time = secs;
|
|
|
|
const seconds = time % 60;
|
|
|
|
|
|
|
|
time /= 60;
|
|
|
|
const minutes = time % 60;
|
|
|
|
|
|
|
|
time /= 60;
|
|
|
|
const hours = minutes % 60;
|
|
|
|
|
|
|
|
const minuteString = `${Math.round(minutes)
|
|
|
|
.toString()
|
|
|
|
.padStart(2)}:${Math.round(seconds).toString().padStart(2, "0")}`;
|
|
|
|
|
|
|
|
if (!showHours) return minuteString;
|
|
|
|
return `${Math.round(hours).toString()}:${minuteString}`;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
const hasHours = durationExceedsHour(videoState.duration);
|
|
|
|
const time = formatSeconds(videoState.time, hasHours);
|
|
|
|
const duration = formatSeconds(videoState.duration, hasHours);
|
|
|
|
|
|
|
|
return (
|
2023-01-09 21:51:24 +01:00
|
|
|
<div className={props.className}>
|
|
|
|
<p className="select-none text-white">
|
|
|
|
{time} / {duration}
|
|
|
|
</p>
|
|
|
|
</div>
|
2023-01-08 21:18:45 +01:00
|
|
|
);
|
|
|
|
}
|