import { Component, createEffect, on } from "solid-js"; import { useVideo } from "../context"; import css from "./seekBar.module.css"; interface SeekBarProps {} export const SeekBar: Component = () => { const video = useVideo(); createEffect( on( () => [video.duration(), video.buffered(), video.currentTime()] as const, ([duration, buffered, currentTime]) => { console.log({ duration, buffered, currentTime }); } ) ); return (
{formatTime(video.currentTime())} {formatTime(video.duration())} video.setTime(e.target.valueAsNumber)} step="0.01" />
); }; const formatTime = (subject: number) => { if (Number.isNaN(subject)) { return ""; } const hours = Math.floor(subject / 3600); const minutes = Math.floor((subject % 3600) / 60); const seconds = Math.floor(subject % 60); const sections = hours !== 0 ? [hours, minutes, seconds] : [minutes, seconds]; return sections.map((section) => String(section).padStart(2, "0")).join(":"); };