From 5ecf1ca00d880048659643976b230ccc0a2eff14 Mon Sep 17 00:00:00 2001 From: wil Date: Mon, 11 Mar 2024 20:18:05 -0400 Subject: [PATCH] playtime cursor also works --- .../common/VideoQuickTrim/VideoQuickTrim.tsx | 32 +++++++++++++++---- .../VideoQuickTrim/components/ProgressBar.tsx | 4 ++- .../components/withScrubbing.tsx | 2 +- .../view/pages/components_library/sandbox.tsx | 10 +++++- .../StudioVST/StudioVSTPage.tsx | 2 ++ .../components/pageVSTApp/pageVSTApp.tsx | 2 ++ 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/packages/fakeyou.com/src/components/common/VideoQuickTrim/VideoQuickTrim.tsx b/packages/fakeyou.com/src/components/common/VideoQuickTrim/VideoQuickTrim.tsx index 46b972f984..8a11af6729 100644 --- a/packages/fakeyou.com/src/components/common/VideoQuickTrim/VideoQuickTrim.tsx +++ b/packages/fakeyou.com/src/components/common/VideoQuickTrim/VideoQuickTrim.tsx @@ -1,6 +1,7 @@ import React, { memo, useCallback, + useEffect, useReducer, useRef, } from "react"; @@ -30,10 +31,14 @@ import './styles.scss' interface VideoQuickTrimProps extends VideoFakeyouProps { onSelect: (values: QuickTrimData) => void; + trimStartSeconds: number; + trimEndSeconds: number; } export const VideoQuickTrim = memo(({ onSelect, + trimStartSeconds: propsTrimStartSeconds, + trimEndSeconds : propsTrimEndSeconds, ...rest }: VideoQuickTrimProps) => { const { t } = useLocalize("VideoPlayerQuickTrim"); @@ -59,12 +64,6 @@ export const VideoQuickTrim = memo(({ type: ACTION_TYPES.ON_LOADED_METADATA, payload:{ videoDuration: node.duration,} }); - //TODO: this sbould be set in USEEFFECT - //IFF USEEFFECT starts working again - // onSelect({ - // trimStartSeconds: 0, - // trimEndSeconds: 3, - // }) }; node.ontimeupdate = ()=>{ @@ -101,6 +100,21 @@ export const VideoQuickTrim = memo(({ compState.isRepeatOn ]); //END videoRefCallback\ + useEffect(()=>{ + if( compState.trimStartSeconds + && compState.trimEndSeconds + && ( + compState.trimStartSeconds !== propsTrimStartSeconds + || compState.trimEndSeconds !== propsTrimEndSeconds + ) + ){ + onSelect({ + trimStartSeconds: compState.trimStartSeconds, + trimEndSeconds: compState.trimEndSeconds, + }); + } + }, [onSelect, compState.trimStartSeconds, compState.trimEndSeconds, propsTrimStartSeconds, propsTrimEndSeconds]) + function videoCanPlay(){ return (compState.playpause === PLAYPUASE_STATES.PAUSED || compState.playpause === PLAYPUASE_STATES.ENDED @@ -162,6 +176,12 @@ export const VideoQuickTrim = memo(({ videoBuffered={videoRef.current?.buffered} videoDuration={compState.videoDuration ||0} dispatchCompState={dispatchCompState} + onPlayCursorChanged={(newPos: number)=>{ + if(videoRef.current !== null && videoRef.current.currentTime + && compState.playbarWidth && compState.videoDuration){ + videoRef.current.currentTime = newPos / compState.playbarWidth * compState.videoDuration; + } + }} /> void; dispatchCompState: (action: Action) => void; })=>{ const playbarRef = useRef(null); @@ -94,7 +96,7 @@ export const ProgressBar = memo(({ /> {console.log(onChangedVal)}} + onChanged={onPlayCursorChanged} boundingWidth={playbarWidth} scrubberWidth={8} /> diff --git a/packages/fakeyou.com/src/components/common/VideoQuickTrim/components/withScrubbing.tsx b/packages/fakeyou.com/src/components/common/VideoQuickTrim/components/withScrubbing.tsx index 9869f67c39..92ba05d760 100644 --- a/packages/fakeyou.com/src/components/common/VideoQuickTrim/components/withScrubbing.tsx +++ b/packages/fakeyou.com/src/components/common/VideoQuickTrim/components/withScrubbing.tsx @@ -106,7 +106,7 @@ export const withScrubbing =

(Component: React.Co if(onScrubChanged && boundingWidth > 0 && prevLeftOffset >= 0 && propsLeftOffset !== prevLeftOffset){ onScrubChanged(prevLeftOffset); } - },[prevLeftOffset, boundingWidth, onScrubChanged]); + },[propsLeftOffset, prevLeftOffset, boundingWidth, onScrubChanged]); useEffect(()=>{ // this takes a forced reset on leftoffset diff --git a/packages/fakeyou.com/src/v2/view/pages/components_library/sandbox.tsx b/packages/fakeyou.com/src/v2/view/pages/components_library/sandbox.tsx index a7600a9c6e..6b5ea067f6 100644 --- a/packages/fakeyou.com/src/v2/view/pages/components_library/sandbox.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/components_library/sandbox.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import VideoQuickTrim from 'components/common/VideoQuickTrim'; import { NavLink } from 'react-router-dom'; @@ -7,9 +7,13 @@ import {Container, Panel} from 'components/common'; export default function ComponentSandbox( {parentPath}:{parentPath:string} ){ + const [state1, setState1] = useState(undefined); + const [state2, setState2] = useState(undefined); const handleCallback = (val:any)=>{ console.log('onChange is triggered') console.log(val); + setState1(val.trimStartSeconds); + setState2(val.trimEndSeconds); } return ( ← Back @@ -18,11 +22,15 @@ export default function ComponentSandbox(


+

{`Start Seconds: ${state1}`}

+

{`Start Seconds: ${state2}`}

{/*
{job.isSuccessful && job.maybe_result ? ( handleOnChange({ diff --git a/packages/fakeyou.com/src/v2/view/pages/video_styletransfer/components/pageVSTApp/pageVSTApp.tsx b/packages/fakeyou.com/src/v2/view/pages/video_styletransfer/components/pageVSTApp/pageVSTApp.tsx index 1fbe3b2d29..3d081a2290 100644 --- a/packages/fakeyou.com/src/v2/view/pages/video_styletransfer/components/pageVSTApp/pageVSTApp.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/video_styletransfer/components/pageVSTApp/pageVSTApp.tsx @@ -70,6 +70,8 @@ export default function PageVSTApp({
handleOnChange({