import type { ReactNode } from 'react'; import { Bar } from './Bar'; import { fmtMs } from '../lib/format'; import { ForwardIcon, FullscreenIcon, PauseIcon, PlayIcon, RewindIcon, SkipNextIcon, } from './icons'; import { t } from '../i18n'; // The one custom player control bar, shared by Watch Together (room /ws // protocol) and Now Playing (bot RPC). Purely presentational: the two sync // channels differ only in the callbacks the views pass in. Embedded players // (YouTube/Twitch/HTML5) always run with native controls hidden; this bar is // the only playback UI. export function PlayerControls(props: { playing: boolean; positionMs: number; durationMs: number; // 0 = unknown live?: boolean; // no seekable timeline (Twitch / generic embeds) canControl: boolean; // transport disabled when false; volume stays local bufferedPct?: number; // 0..100 second fill on the seek bar volumePct: number; // 0..100 volumeLive?: boolean; // apply volume while dragging (local volume) onTogglePlay: () => void; onSeekMs: (ms: number) => void; onSeekBy?: (deltaSec: number) => void; // renders ±10s when present onVolume: (pct: number) => void; onSkip?: () => void; // renders next-track button when present skipDisabled?: boolean; onFullscreen?: () => void; settings?: ReactNode; showLocal?: boolean; // hide the volume/quality row (default shown) extra?: ReactNode; // view-specific buttons after the seek bar extraLocal?: ReactNode; // view-specific controls in the volume row }) { const { live, durationMs, positionMs, canControl } = props; const progressPct = live ? 100 : durationMs > 0 ? Math.min(100, (positionMs / durationMs) * 100) : 0; return (
{!live && props.onSeekBy && ( <> )} {props.onSkip && ( )} {live ? '—' : fmtMs(positionMs)} live || !durationMs ? t('LIVE') : fmtMs(Math.round(f * durationMs)) } onDragStart={() => !live && durationMs > 0} onCommit={(f) => props.onSeekMs(Math.round(f * durationMs))} /> {live ? t('LIVE') : fmtMs(durationMs)} {props.extra}
{(props.showLocal ?? true) && (
{t('Vol')} `${Math.round(f * 100)}%`} onCommit={(f) => props.onVolume(Math.round(f * 100))} /> {Math.round(props.volumePct)}% {props.settings} {props.onFullscreen && ( )} {props.extraLocal}
)}
); }