mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-17 15:15:17 +00:00
playtime cursor also works
This commit is contained in:
1 parent
5adc572fcf
commit
5ecf1ca00d
6 files changed
+43
-9
No files matched your search
@@ -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;
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<ControlBar
|
||||
readyToMount={(compState.status === STATE_STATUSES.VIDEO_METADATA_LOADED)}
|
||||
|
||||
+3
-1
@@ -20,6 +20,7 @@ export const ProgressBar = memo(({
|
||||
scrubberWidth,
|
||||
videoDuration,
|
||||
videoBuffered,
|
||||
onPlayCursorChanged,
|
||||
dispatchCompState
|
||||
}:{
|
||||
readyToMount: boolean;
|
||||
@@ -30,6 +31,7 @@ export const ProgressBar = memo(({
|
||||
scrubberWidth: number;
|
||||
videoDuration: number;
|
||||
videoBuffered:TimeRanges | undefined;
|
||||
onPlayCursorChanged: (newPos: number) => void;
|
||||
dispatchCompState: (action: Action) => void;
|
||||
})=>{
|
||||
const playbarRef = useRef<HTMLDivElement | null>(null);
|
||||
@@ -94,7 +96,7 @@ export const ProgressBar = memo(({
|
||||
/>
|
||||
<PlayCursor
|
||||
scrubPosition={timeCursorOffset}
|
||||
onChanged={(onChangedVal)=>{console.log(onChangedVal)}}
|
||||
onChanged={onPlayCursorChanged}
|
||||
boundingWidth={playbarWidth}
|
||||
scrubberWidth={8}
|
||||
/>
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ export const withScrubbing = <P extends withScrubbingPropsI>(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
|
||||
|
||||
@@ -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<number|string|boolean|undefined>(undefined);
|
||||
const [state2, setState2] = useState<number|string|boolean|undefined>(undefined);
|
||||
const handleCallback = (val:any)=>{
|
||||
console.log('onChange is triggered')
|
||||
console.log(val);
|
||||
setState1(val.trimStartSeconds);
|
||||
setState2(val.trimEndSeconds);
|
||||
}
|
||||
return (<Container>
|
||||
<NavLink to={`${parentPath}`}>← Back</NavLink>
|
||||
@@ -18,11 +22,15 @@ export default function ComponentSandbox(
|
||||
|
||||
<div className="m-4">
|
||||
<VideoQuickTrim
|
||||
trimStartSeconds={Number(state1 ||0)}
|
||||
trimEndSeconds={Number(state2 || 0)}
|
||||
onSelect={handleCallback}
|
||||
mediaToken='m_wdptbe5rfzpb1gzhva78gpw8qrkgs9'
|
||||
/>
|
||||
</div>
|
||||
<br/>
|
||||
<p>{`Start Seconds: ${state1}`}</p>
|
||||
<p>{`Start Seconds: ${state2}`}</p>
|
||||
{/* <br/>
|
||||
<div className="m-4">
|
||||
<VideoQuickTrim
|
||||
|
||||
+2
@@ -126,6 +126,8 @@ export default function PageVSTApp() {
|
||||
<div className="col-12 col-md-6">
|
||||
{job.isSuccessful && job.maybe_result ? (
|
||||
<VideoQuickTrim
|
||||
trimStartSeconds={0}
|
||||
trimEndSeconds={0}
|
||||
mediaToken={job.maybe_result.entity_token}
|
||||
onSelect={(val: QuickTrimData) =>
|
||||
handleOnChange({
|
||||
|
||||
+2
@@ -70,6 +70,8 @@ export default function PageVSTApp({
|
||||
<div className="row g-5 mb-4">
|
||||
<div className="col-12 col-md-6">
|
||||
<VideoQuickTrim
|
||||
trimStartSeconds={vstValues.trimStart}
|
||||
trimEndSeconds={vstValues.trimEnd}
|
||||
mediaToken={vstValues.fileToken}
|
||||
onSelect={(val: QuickTrimData) =>
|
||||
handleOnChange({
|
||||
|
||||
Reference in new issue
Block a user