Create polished demo videos without editing skills. Mac/Windows/Linux
skip trimmed area seeking
Siddharth2b7cea0b550d
diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsxindex e9b2d1f1..b67f6c76 100644--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@ -390,6 +390,7 @@ export default function VideoEditor() {shadowIntensity={shadowIntensity}showBlur={showBlur}cropRegion={cropRegion}+ trimRegions={trimRegions}/></div></div>diff --git a/src/components/video-editor/VideoPlayback.tsx b/src/components/video-editor/VideoPlayback.tsxindex 74cec085..197acb6b 100644--- a/src/components/video-editor/VideoPlayback.tsx+++ b/src/components/video-editor/VideoPlayback.tsx@@ -2,7 +2,7 @@ import type React from "react";import { useEffect, useRef, useImperativeHandle, forwardRef, useState, useMemo, useCallback } from "react";import { getAssetPath } from "@/lib/assetPath";import { Application, Container, Sprite, Graphics, BlurFilter, Texture, VideoSource } from 'pixi.js';-import { ZOOM_DEPTH_SCALES, type ZoomRegion, type ZoomFocus, type ZoomDepth } from "./types";+import { ZOOM_DEPTH_SCALES, type ZoomRegion, type ZoomFocus, type ZoomDepth, type TrimRegion } from "./types";import { DEFAULT_FOCUS, SMOOTHING_FACTOR, MIN_DELTA } from "./videoPlayback/constants";import { clamp01 } from "./videoPlayback/mathUtils";import { findDominantRegion } from "./videoPlayback/zoomRegionUtils";@@ -28,6 +28,7 @@ interface VideoPlaybackProps {shadowIntensity?: number;showBlur?: boolean;cropRegion?: import('./types').CropRegion;+ trimRegions?: TrimRegion[];}export interface VideoPlaybackRef {@@ -55,6 +56,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(({shadowIntensity = 0,showBlur,cropRegion,+ trimRegions = [],}, ref) => {const videoRef = useRef<HTMLVideoElement | null>(null);const containerRef = useRef<HTMLDivElement | null>(null);@@ -85,6 +87,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(({const allowPlaybackRef = useRef(false);const lockedVideoDimensionsRef = useRef<{ width: number; height: number } | null>(null);const layoutVideoContentRef = useRef<(() => void) | null>(null);+ const trimRegionsRef = useRef<TrimRegion[]>([]);const clampFocusToStage = useCallback((focus: ZoomFocus, depth: ZoomDepth) => {return clampFocusToStageUtil(focus, depth, stageSizeRef.current);@@ -287,6 +290,10 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(({isPlayingRef.current = isPlaying;}, [isPlaying]);+ useEffect(() => {+ trimRegionsRef.current = trimRegions;+ }, [trimRegions]);+useEffect(() => {if (!pixiReady || !videoReady) return;@@ -513,6 +520,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(({timeUpdateAnimationRef,onPlayStateChange,onTimeUpdate,+ trimRegionsRef,});video.addEventListener('play', handlePlay);diff --git a/src/components/video-editor/videoPlayback/videoEventHandlers.ts b/src/components/video-editor/videoPlayback/videoEventHandlers.tsindex 86b8201f..8a55545d 100644--- a/src/components/video-editor/videoPlayback/videoEventHandlers.ts+++ b/src/components/video-editor/videoPlayback/videoEventHandlers.ts@@ -1,4 +1,5 @@import type React from 'react';+import type { TrimRegion } from '../types';interface VideoEventHandlersParams {video: HTMLVideoElement;@@ -9,6 +10,7 @@ interface VideoEventHandlersParams {timeUpdateAnimationRef: React.MutableRefObject<number | null>;onPlayStateChange: (playing: boolean) => void;onTimeUpdate: (time: number) => void;+ trimRegionsRef: React.MutableRefObject<TrimRegion[]>;}export function createVideoEventHandlers(params: VideoEventHandlersParams) {@@ -21,6 +23,7 @@ export function createVideoEventHandlers(params: VideoEventHandlersParams) {timeUpdateAnimationRef,onPlayStateChange,onTimeUpdate,+ trimRegionsRef,} = params;const emitTime = (timeValue: number) => {@@ -28,9 +31,35 @@ export function createVideoEventHandlers(params: VideoEventHandlersParams) {onTimeUpdate(timeValue);};+ // Helper function to check if current time is within a trim region+ const findActiveTrimRegion = (currentTimeMs: number): TrimRegion | null => {+ const trimRegions = trimRegionsRef.current;+ return trimRegions.find(+ (region) => currentTimeMs >= region.startMs && currentTimeMs < region.endMs+ ) || null;+ };+function updateTime() {if (!video) return;- emitTime(video.currentTime);++ const currentTimeMs = video.currentTime * 1000;+ const activeTrimRegion = findActiveTrimRegion(currentTimeMs);++ // If we're in a trim region during playback, skip to the end of it+ if (activeTrimRegion && !video.paused && !video.ended) {+ const skipToTime = activeTrimRegion.endMs / 1000;++ // If the skip would take us past the video duration, pause instead+ if (skipToTime >= video.duration) {+ video.pause();+ } else {+ video.currentTime = skipToTime;+ emitTime(skipToTime);+ }+ } else {+ emitTime(video.currentTime);+ }+if (!video.paused && !video.ended) {timeUpdateAnimationRef.current = requestAnimationFrame(updateTime);}@@ -68,10 +97,25 @@ export function createVideoEventHandlers(params: VideoEventHandlersParams) {const handleSeeked = () => {isSeekingRef.current = false;- if (!isPlayingRef.current && !video.paused) {- video.pause();+ const currentTimeMs = video.currentTime * 1000;+ const activeTrimRegion = findActiveTrimRegion(currentTimeMs);++ // If we seeked into a trim region while playing, skip to the end+ if (activeTrimRegion && isPlayingRef.current && !video.paused) {+ const skipToTime = activeTrimRegion.endMs / 1000;++ if (skipToTime >= video.duration) {+ video.pause();+ } else {+ video.currentTime = skipToTime;+ emitTime(skipToTime);+ }+ } else {+ if (!isPlayingRef.current && !video.paused) {+ video.pause();+ }+ emitTime(video.currentTime);}- emitTime(video.currentTime);};const handleSeeking = () => {