feat(playlist): seamless playback of selected shots, cut only
Deploy / deploy (push) Successful in 3m12s
Deploy / deploy (push) Successful in 3m12s
Check shots on the Playlist page and "Play selection" plays them back to back without slate or handles. The cut comes from the version's handle and slate metadata (new cutSpan in lib/handles); the media is never changed. SequencePlayer double-buffers two videos: the next clip is parked a few frames before its cut-in and pre-rolled hidden, the outgoing clip pauses on its last cut frame, and the cut fires on the incoming clip's cut-in frame (requestVideoFrameCallback), with the start time calibrated at each cut. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useRef, useCallback } from "react";
|
||||
import { useState, useEffect, useRef, useCallback, useMemo, startTransition } from "react";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { ReviewPlayer, type ReviewPlayerRef } from "@/components/player/ReviewPlayer";
|
||||
import { SequencePlayer, type SequenceClip } from "@/components/player/SequencePlayer";
|
||||
import { useReviewStore } from "@/hooks/use-review-player";
|
||||
import {
|
||||
Select,
|
||||
@@ -26,6 +27,8 @@ import {
|
||||
ExternalLink,
|
||||
ShieldCheck,
|
||||
Send,
|
||||
ListVideo,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
|
||||
interface Project {
|
||||
@@ -42,6 +45,7 @@ interface PlaylistVersion {
|
||||
thumbnailUrl: string | null;
|
||||
posterUrl: string | null;
|
||||
fps: number;
|
||||
duration?: number | null;
|
||||
frameCount?: number | null;
|
||||
hqFileUrl?: string | null;
|
||||
handleHead?: number | null;
|
||||
@@ -91,6 +95,10 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
||||
const [activeShot, setActiveShot] = useState<PlaylistShot | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isActioning, setIsActioning] = useState(false);
|
||||
/** Shots checked for the seamless playlist, by shot id. */
|
||||
const [selected, setSelected] = useState<Set<string>>(new Set());
|
||||
const [sequenceMode, setSequenceMode] = useState(false);
|
||||
const lastChecked = useRef<string | null>(null);
|
||||
|
||||
const canApprove = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(userRole);
|
||||
|
||||
@@ -117,6 +125,9 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
||||
if (cancelled) return;
|
||||
const list: PlaylistShot[] = data.shots ?? [];
|
||||
setShots(list);
|
||||
setSelected(loadSelection(projectId, list));
|
||||
lastChecked.current = null;
|
||||
setSequenceMode(false);
|
||||
// Auto-select the first shot, or keep the current one if it still exists
|
||||
setActiveShot((prev) => {
|
||||
const stillExists = prev && list.some((s) => s.id === prev.id);
|
||||
@@ -139,9 +150,78 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
||||
|
||||
const handleSelectShot = useCallback((shot: PlaylistShot) => {
|
||||
reset();
|
||||
setSequenceMode(false);
|
||||
setActiveShot(shot);
|
||||
}, [reset]);
|
||||
|
||||
const updateSelection = useCallback(
|
||||
(next: Set<string>) => {
|
||||
setSelected(next);
|
||||
if (projectId) saveSelection(projectId, next);
|
||||
if (next.size === 0) setSequenceMode(false);
|
||||
},
|
||||
[projectId]
|
||||
);
|
||||
|
||||
/** Toggle one shot; shift-click sets every shot between it and the last one checked. */
|
||||
const toggleChecked = (shot: PlaylistShot, shift: boolean) => {
|
||||
const next = new Set(selected);
|
||||
const on = !selected.has(shot.id);
|
||||
const from = lastChecked.current ? shots.findIndex((s) => s.id === lastChecked.current) : -1;
|
||||
const to = shots.findIndex((s) => s.id === shot.id);
|
||||
const range = shift && from >= 0 ? shots.slice(Math.min(from, to), Math.max(from, to) + 1) : [shot];
|
||||
for (const s of range) {
|
||||
if (on) next.add(s.id);
|
||||
else next.delete(s.id);
|
||||
}
|
||||
lastChecked.current = shot.id;
|
||||
updateSelection(next);
|
||||
};
|
||||
|
||||
const setGroupChecked = (group: PlaylistShot[], on: boolean) => {
|
||||
const next = new Set(selected);
|
||||
for (const s of group) {
|
||||
if (on) next.add(s.id);
|
||||
else next.delete(s.id);
|
||||
}
|
||||
updateSelection(next);
|
||||
};
|
||||
|
||||
// The playlist, in edit order. Keyed on the versions it plays so a refresh
|
||||
// (e.g. after approving a shot) doesn't restart playback.
|
||||
const clipKey = shots
|
||||
.filter((s) => selected.has(s.id))
|
||||
.map((s) => s.latestVersion.id)
|
||||
.join(",");
|
||||
const clips = useMemo<SequenceClip[]>(
|
||||
() =>
|
||||
shots
|
||||
.filter((s) => selected.has(s.id))
|
||||
.map((s) => ({
|
||||
id: s.latestVersion.id,
|
||||
label: s.shotCode,
|
||||
sublabel: `v${String(s.latestVersion.versionNumber).padStart(3, "0")}`,
|
||||
url: s.latestVersion.fileUrl,
|
||||
hqUrl: s.latestVersion.hqFileUrl,
|
||||
fps: s.latestVersion.fps,
|
||||
duration: s.latestVersion.duration,
|
||||
handles: s.latestVersion,
|
||||
})),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[clipKey]
|
||||
);
|
||||
|
||||
const handleClipChange = useCallback(
|
||||
(clip: SequenceClip) => {
|
||||
// A transition, so re-rendering the page (shot list and all) yields to
|
||||
// the video: rendered in one go, it dropped the frame after every cut.
|
||||
startTransition(() => {
|
||||
setActiveShot(shots.find((s) => s.latestVersion.id === clip.id) ?? null);
|
||||
});
|
||||
},
|
||||
[shots]
|
||||
);
|
||||
|
||||
const refreshShots = useCallback(() => {
|
||||
if (!projectId) return;
|
||||
fetch(`/api/playlist?projectId=${projectId}`)
|
||||
@@ -220,6 +300,33 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{selected.size > 0 && (
|
||||
sequenceMode ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setSequenceMode(false)}
|
||||
className="h-7 text-xs gap-1"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
Exit playlist
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
reset();
|
||||
setSequenceMode(true);
|
||||
}}
|
||||
className="h-7 text-xs gap-1"
|
||||
title="Play the checked shots back to back: cut only, no slate or handles"
|
||||
>
|
||||
<ListVideo className="h-3.5 w-3.5" />
|
||||
Play selection ({selected.size})
|
||||
</Button>
|
||||
)
|
||||
)}
|
||||
|
||||
{activeShot && (
|
||||
<div className="flex items-center gap-2 ml-auto">
|
||||
<span className="font-mono text-sm text-white">{activeShot.shotCode}</span>
|
||||
@@ -272,7 +379,9 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
||||
<div className="flex flex-1 min-h-0 overflow-hidden">
|
||||
{/* Player */}
|
||||
<div className="flex-1 min-w-0 bg-black flex flex-col">
|
||||
{activeShot ? (
|
||||
{sequenceMode && clips.length > 0 ? (
|
||||
<SequencePlayer clips={clips} onClipChange={handleClipChange} />
|
||||
) : activeShot ? (
|
||||
<ReviewPlayer
|
||||
key={activeShot.latestVersion.id}
|
||||
ref={playerRef}
|
||||
@@ -304,7 +413,26 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
||||
<div className="px-3 py-2.5 border-b border-border shrink-0 flex items-center justify-between">
|
||||
<span className="text-xs font-medium text-zinc-400 uppercase tracking-wider">Shots</span>
|
||||
{shots.length > 0 && (
|
||||
<span className="text-xs text-zinc-600">{shots.length}</span>
|
||||
<div className="flex items-center gap-2 text-xs">
|
||||
{selected.size > 0 ? (
|
||||
<button
|
||||
onClick={() => updateSelection(new Set())}
|
||||
className="text-zinc-500 hover:text-zinc-200"
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => setGroupChecked(shots, true)}
|
||||
className="text-zinc-500 hover:text-zinc-200"
|
||||
>
|
||||
Select all
|
||||
</button>
|
||||
)}
|
||||
<span className="text-zinc-600">
|
||||
{selected.size > 0 ? `${selected.size}/${shots.length}` : shots.length}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -327,16 +455,25 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
||||
<div>
|
||||
{episodeGroups.map(([episode, episodeShots]) => (
|
||||
<div key={episode}>
|
||||
<div className="px-3 py-1.5 bg-zinc-900/80 sticky top-0 z-10 border-b border-zinc-800">
|
||||
<label className="px-3 py-1.5 bg-zinc-900/80 sticky top-0 z-10 border-b border-zinc-800 flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="h-3 w-3 accent-blue-500 cursor-pointer"
|
||||
checked={episodeShots.every((s) => selected.has(s.id))}
|
||||
onChange={(e) => setGroupChecked(episodeShots, e.target.checked)}
|
||||
title="Select this episode"
|
||||
/>
|
||||
<span className="text-[10px] font-semibold text-zinc-500 uppercase tracking-wider">
|
||||
Ep {episode}
|
||||
</span>
|
||||
</div>
|
||||
</label>
|
||||
{episodeShots.map((shot) => (
|
||||
<ShotThumbnail
|
||||
key={shot.id}
|
||||
shot={shot}
|
||||
isActive={activeShot?.id === shot.id}
|
||||
isChecked={selected.has(shot.id)}
|
||||
onToggle={(shift) => toggleChecked(shot, shift)}
|
||||
onClick={() => handleSelectShot(shot)}
|
||||
/>
|
||||
))}
|
||||
@@ -350,6 +487,8 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
||||
key={shot.id}
|
||||
shot={shot}
|
||||
isActive={activeShot?.id === shot.id}
|
||||
isChecked={selected.has(shot.id)}
|
||||
onToggle={(shift) => toggleChecked(shot, shift)}
|
||||
onClick={() => handleSelectShot(shot)}
|
||||
/>
|
||||
))}
|
||||
@@ -365,25 +504,45 @@ export function PlaylistClient({ projects, userRole }: PlaylistClientProps) {
|
||||
function ShotThumbnail({
|
||||
shot,
|
||||
isActive,
|
||||
isChecked,
|
||||
onToggle,
|
||||
onClick,
|
||||
}: {
|
||||
shot: PlaylistShot;
|
||||
isActive: boolean;
|
||||
isChecked: boolean;
|
||||
onToggle: (shift: boolean) => void;
|
||||
onClick: () => void;
|
||||
}) {
|
||||
const thumb = shot.latestVersion.thumbnailUrl ?? shot.latestVersion.posterUrl ?? shot.thumbnailUrl;
|
||||
const ApprovalIcon = APPROVAL_ICONS[shot.latestVersion.approvalStatus] ?? Clock;
|
||||
|
||||
return (
|
||||
<button
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={onClick}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") onClick();
|
||||
}}
|
||||
className={cn(
|
||||
"w-full flex items-start gap-2.5 px-3 py-2.5 text-left transition-colors border-b border-zinc-800/60 group",
|
||||
"w-full flex items-start gap-2.5 px-3 py-2.5 text-left transition-colors border-b border-zinc-800/60 group cursor-pointer",
|
||||
isActive
|
||||
? "bg-blue-500/10 border-l-2 border-l-blue-500"
|
||||
: "hover:bg-zinc-800/40 border-l-2 border-l-transparent"
|
||||
)}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={isChecked}
|
||||
onChange={() => {}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onToggle(e.shiftKey);
|
||||
}}
|
||||
className="mt-3 h-3.5 w-3.5 shrink-0 accent-blue-500 cursor-pointer"
|
||||
title="Add to playlist (shift-click for a range)"
|
||||
/>
|
||||
{/* Thumbnail */}
|
||||
<div className="w-20 aspect-[2.39/1] rounded overflow-hidden bg-zinc-800 shrink-0 flex items-center justify-center">
|
||||
{thumb ? (
|
||||
@@ -415,6 +574,28 @@ function ShotThumbnail({
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const selectionKey = (projectId: string) => `playlist:selection:${projectId}`;
|
||||
|
||||
/** The checked shots remembered for this project, minus any no longer listed. */
|
||||
function loadSelection(projectId: string, shots: PlaylistShot[]): Set<string> {
|
||||
try {
|
||||
const ids: unknown = JSON.parse(localStorage.getItem(selectionKey(projectId)) ?? "[]");
|
||||
if (!Array.isArray(ids)) return new Set();
|
||||
const listed = new Set(shots.map((s) => s.id));
|
||||
return new Set(ids.filter((id): id is string => typeof id === "string" && listed.has(id)));
|
||||
} catch {
|
||||
return new Set();
|
||||
}
|
||||
}
|
||||
|
||||
function saveSelection(projectId: string, selected: Set<string>) {
|
||||
try {
|
||||
localStorage.setItem(selectionKey(projectId), JSON.stringify([...selected]));
|
||||
} catch {
|
||||
// Storage unavailable: the selection just isn't remembered.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ export async function GET(req: NextRequest) {
|
||||
thumbnailUrl: true,
|
||||
posterUrl: true,
|
||||
fps: true,
|
||||
duration: true,
|
||||
frameCount: true,
|
||||
hqFileUrl: true,
|
||||
handleHead: true,
|
||||
@@ -90,6 +91,7 @@ export async function GET(req: NextRequest) {
|
||||
thumbnailUrl: latest.thumbnailUrl,
|
||||
posterUrl: latest.posterUrl,
|
||||
fps: latest.fps,
|
||||
duration: latest.duration,
|
||||
frameCount: latest.frameCount,
|
||||
hqFileUrl: latest.hqFileUrl,
|
||||
handleHead: latest.handleHead,
|
||||
|
||||
Reference in New Issue
Block a user