Skip to content

🎥 Make videos programmatically with React

done

Jonny Burgerd0d319b77afb
diff --git a/packages/player/src/PlayerControls.tsx b/packages/player/src/PlayerControls.tsx
index 50fd5e0c8a..69b6a1957e 100644
--- a/packages/player/src/PlayerControls.tsx
+++ b/packages/player/src/PlayerControls.tsx
@@ -94,6 +94,8 @@ export const Controls: React.FC<{
spaceKeyToPlayOrPause: boolean;
onSeekEnd: () => void;
onSeekStart: () => void;
+ inFrame: number | null;
+ outFrame: number | null;
}> = ({
durationInFrames,
hovered,
@@ -107,6 +109,8 @@ export const Controls: React.FC<{
spaceKeyToPlayOrPause,
onSeekEnd,
onSeekStart,
+ inFrame,
+ outFrame,
}) => {
const playButtonRef = useRef<HTMLButtonElement | null>(null);
const frame = Internals.Timeline.useTimelinePosition();
@@ -189,6 +193,8 @@ export const Controls: React.FC<{
onSeekEnd={onSeekEnd}
onSeekStart={onSeekStart}
durationInFrames={durationInFrames}
+ inFrame={inFrame}
+ outFrame={outFrame}
/>
</div>
);
diff --git a/packages/player/src/PlayerSeekBar.tsx b/packages/player/src/PlayerSeekBar.tsx
index 944544ba09..49b270e8b1 100644
--- a/packages/player/src/PlayerSeekBar.tsx
+++ b/packages/player/src/PlayerSeekBar.tsx
@@ -35,7 +35,7 @@ const containerStyle: React.CSSProperties = {
const barBackground: React.CSSProperties = {
height: BAR_HEIGHT,
- backgroundColor: 'rgba(255, 255, 255, 0.5)',
+ backgroundColor: 'rgba(255, 255, 255, 0.25)',
width: '100%',
borderRadius: BAR_HEIGHT / 2,
};
@@ -54,7 +54,9 @@ export const PlayerSeekBar: React.FC<{
durationInFrames: number;
onSeekStart: () => void;
onSeekEnd: () => void;
-}> = ({durationInFrames, onSeekEnd, onSeekStart}) => {
+ inFrame: number | null;
+ outFrame: number | null;
+}> = ({durationInFrames, onSeekEnd, onSeekStart, inFrame, outFrame}) => {
const containerRef = useRef<HTMLDivElement>(null);
const barHovered = useHoverState(containerRef);
const size = useElementSize(containerRef, {
@@ -174,10 +176,26 @@ export const PlayerSeekBar: React.FC<{
return {
height: BAR_HEIGHT,
backgroundColor: 'rgba(255, 255, 255, 1)',
- width: (frame / (durationInFrames - 1)) * 100 + '%',
+ width: ((frame - (inFrame ?? 0)) / (durationInFrames - 1)) * 100 + '%',
+ marginLeft: ((inFrame ?? 0) / (durationInFrames - 1)) * 100 + '%',
borderRadius: BAR_HEIGHT / 2,
};
- }, [durationInFrames, frame]);
+ }, [durationInFrames, frame, inFrame]);
+
+ const active: React.CSSProperties = useMemo(() => {
+ return {
+ height: BAR_HEIGHT,
+ backgroundColor: 'rgba(255, 255, 255, 0.25)',
+ width:
+ (((outFrame ?? durationInFrames - 1) - (inFrame ?? 0)) /
+ (durationInFrames - 1)) *
+ 100 +
+ '%',
+ marginLeft: ((inFrame ?? 0) / (durationInFrames - 1)) * 100 + '%',
+ borderRadius: BAR_HEIGHT / 2,
+ position: 'absolute',
+ };
+ }, [durationInFrames, inFrame, outFrame]);
return (
<div
@@ -186,6 +204,7 @@ export const PlayerSeekBar: React.FC<{
style={containerStyle}
>
<div style={barBackground}>
+ <div style={active} />
<div style={fillStyle} />
</div>
<div style={knobStyle} />
diff --git a/packages/player/src/PlayerUI.tsx b/packages/player/src/PlayerUI.tsx
index 9266f88ba9..d504d52760 100644
--- a/packages/player/src/PlayerUI.tsx
+++ b/packages/player/src/PlayerUI.tsx
@@ -528,6 +528,8 @@ const PlayerUI: React.ForwardRefRenderFunction<
spaceKeyToPlayOrPause={spaceKeyToPlayOrPause}
onSeekEnd={onSeekEnd}
onSeekStart={onSeekStart}
+ inFrame={inFrame}
+ outFrame={outFrame}
/>
) : null}
</>