Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): review recordings with seekable MediaPlayer preview

Richie McIlroyc2b32484ad1f
diff --git a/apps/web/app/s/[videoId]/_components/timeline/recording/MediaPreviewPanel.tsx b/apps/web/app/s/[videoId]/_components/timeline/recording/MediaPreviewPanel.tsx
index b9d0dcc05..02ba2903d 100644
--- a/apps/web/app/s/[videoId]/_components/timeline/recording/MediaPreviewPanel.tsx
+++ b/apps/web/app/s/[videoId]/_components/timeline/recording/MediaPreviewPanel.tsx
@@ -1,10 +1,25 @@
"use client";
-import { useEffect, useMemo } from "react";
-import { formatMediaDuration } from "../../media-comment/format-media-duration";
+import { useEffect, useState } from "react";
+import {
+ MediaPlayer,
+ MediaPlayerControls,
+ MediaPlayerControlsOverlay,
+ MediaPlayerPlay,
+ MediaPlayerPlaybackSpeed,
+ MediaPlayerSeek,
+ MediaPlayerTime,
+ MediaPlayerVideo,
+ MediaPlayerVolume,
+} from "../../video/media-player";
import { formatClock } from "../timeline-format";
-/** Stop → look at it → send or retake. The blob loops muted until sent. */
+/**
+ * Stop → review → send or retake. A real (mini) player, not a silent loop:
+ * checking the take means scrubbing it and hearing it, so the preview gets
+ * the share player's own seek/volume/speed controls, always visible (no
+ * autoHide — a review surface shouldn't make you hunt for the bar).
+ */
export function MediaPreviewPanel({
blob,
durationSeconds,
@@ -18,29 +33,51 @@ export function MediaPreviewPanel({
onSend: () => void;
onDiscard: () => void;
}) {
- const previewUrl = useMemo(() => URL.createObjectURL(blob), [blob]);
- useEffect(() => () => URL.revokeObjectURL(previewUrl), [previewUrl]);
+ // Created in an effect, not useMemo: the memo survives StrictMode's
+ // mount→cleanup→remount cycle but the cleanup's revoke does not — the
+ // remount kept a revoked URL and the preview rendered black (send still
+ // worked; the upload uses the blob, not the URL).
+ const [previewUrl, setPreviewUrl] = useState<string | null>(null);
+ useEffect(() => {
+ const url = URL.createObjectURL(blob);
+ setPreviewUrl(url);
+ return () => URL.revokeObjectURL(url);
+ }, [blob]);
return (
- <div className="new-card-style flex w-80 flex-col gap-2 p-2.5">
+ <div className="new-card-style flex w-96 max-w-full flex-col gap-2 p-2.5">
<div className="relative aspect-video w-full overflow-hidden rounded-xl bg-gray-3">
- {/* biome-ignore lint/a11y/useMediaCaption: preview of the author's own recording */}
- <video
- src={previewUrl}
- autoPlay
- muted
- loop
- playsInline
- className="size-full object-contain"
- />
- <span className="absolute right-1.5 bottom-1.5 rounded bg-black/60 px-1.5 py-0.5 text-[10px] tabular-nums text-white">
- {formatMediaDuration(durationSeconds)}
- </span>
+ {previewUrl && (
+ <MediaPlayer
+ label="Recording preview"
+ className="size-full rounded-xl bg-black"
+ >
+ <MediaPlayerVideo
+ src={previewUrl}
+ autoPlay
+ playsInline
+ className="size-full object-contain"
+ />
+ <MediaPlayerControls className="flex-col items-start gap-1.5">
+ <MediaPlayerControlsOverlay className="rounded-b-xl" />
+ <MediaPlayerSeek fallbackDuration={durationSeconds} />
+ <div className="flex w-full items-center gap-1.5">
+ <MediaPlayerPlay />
+ <MediaPlayerVolume expandable />
+ <MediaPlayerTime fallbackDuration={durationSeconds} />
+ <div className="flex-1" />
+ <MediaPlayerPlaybackSpeed />
+ </div>
+ </MediaPlayerControls>
+ </MediaPlayer>
+ )}
</div>
<div className="flex items-center gap-1.5">
- <span className="rounded-md bg-gray-2 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-gray-11 ring-1 ring-gray-4">
- {formatClock(timestamp)}
- </span>
+ {timestamp > 0 && (
+ <span className="rounded-md bg-gray-2 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-gray-11 ring-1 ring-gray-4">
+ {formatClock(timestamp)}
+ </span>
+ )}
<div className="flex-1" />
<button
type="button"