Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 37x 37x 37x 37x 37x 3x 3x 20x 20x 20x 20x | /** A playback position as a video player shows it: `m:ss`, or `h:mm:ss` from an hour. Negative times read as 0. */
export function formatPlaybackTime(seconds: number): string {
const whole = Number.isFinite(seconds) ? Math.max(0, Math.floor(seconds)) : 0;
const hours = Math.floor(whole / 3600);
const minutes = Math.floor((whole % 3600) / 60);
const rest = String(whole % 60).padStart(2, '0');
return hours > 0 ? `${hours}:${String(minutes).padStart(2, '0')}:${rest}` : `${minutes}:${rest}`;
}
/** Where a seek by `deltaSeconds` from `currentSeconds` lands, kept inside the chart (`0..durationSeconds`). */
export function resolveSeekTarget(currentSeconds: number, deltaSeconds: number, durationSeconds: number): number {
const end = Number.isFinite(durationSeconds) ? Math.max(0, durationSeconds) : 0;
return Math.max(0, Math.min(end, currentSeconds + deltaSeconds));
}
/**
* The second the seek bar shows. While the thumb is held, `heldSeconds` wins so the play clock cannot pull it back;
* otherwise the bar follows `currentSeconds`. Both are kept inside the chart.
*/
export function resolvePlaybackSeconds(currentSeconds: number, durationSeconds: number, heldSeconds?: number): number {
const end = Number.isFinite(durationSeconds) ? Math.max(0, durationSeconds) : 0;
const held = heldSeconds !== undefined && Number.isFinite(heldSeconds) ? heldSeconds : currentSeconds;
const seconds = Number.isFinite(held) ? held : 0;
return Math.max(0, Math.min(end, seconds));
}
|