🎥 Make videos programmatically with React
revisit player seeking
Jonny Burger2491d934e97a
diff --git a/packages/core/src/use-media-playback.ts b/packages/core/src/use-media-playback.tsindex ae4b323f4c..573bf20e36 100644--- a/packages/core/src/use-media-playback.ts+++ b/packages/core/src/use-media-playback.ts@@ -56,9 +56,12 @@ export const useMediaPlayback = ({);}- mediaRef.current.playbackRate = Math.max(0, playbackRate);+ const playbackRateToSet = Math.max(0, playbackRate);+ if (mediaRef.current.playbackRate !== playbackRateToSet) {+ mediaRef.current.playbackRate = playbackRateToSet;+ }- const shouldBeTime = getMediaTime({+ const _shouldBeTime = getMediaTime({fps,frame,src,@@ -66,12 +69,24 @@ export const useMediaPlayback = ({startFrom: -mediaStartsAt,mediaType,});+ const {duration} = mediaRef.current;+ const shouldBeTime =+ !Number.isNaN(duration) && Number.isFinite(duration)+ ? Math.min(duration, _shouldBeTime)+ : _shouldBeTime;const isTime = mediaRef.current.currentTime;const timeShift = Math.abs(shouldBeTime - isTime);- if (timeShift > acceptableTimeshift && !mediaRef.current.ended) {+ if (timeShift > acceptableTimeshift) {// If scrubbing around, adjust timing- // or if time shift is bigger than 0.2sec+ // or if time shift is bigger than 0.45sec++ console.log(+ 'seekingA',+ timeShift,+ mediaRef.current.currentTime,+ shouldBeTime+ );mediaRef.current.currentTime = shouldBeTime;if (!onlyWarnForMediaSeekingError) {warnAboutNonSeekableMedia(@@ -91,12 +106,14 @@ export const useMediaPlayback = ({if (!playing || absoluteFrame === 0) {if (makesSenseToSeek) {+ console.log('seekingB');mediaRef.current.currentTime = shouldBeTime;}}if (mediaRef.current.paused && !mediaRef.current.ended && playing) {if (makesSenseToSeek) {+ console.log('seekingC');mediaRef.current.currentTime = shouldBeTime;}diff --git a/packages/player-example/pages/index.tsx b/packages/player-example/pages/index.tsxindex 9ab969055f..4ad3bfd780 100644--- a/packages/player-example/pages/index.tsx+++ b/packages/player-example/pages/index.tsx@@ -19,7 +19,7 @@ const Car = () =>function Index() {return (- <React.StrictMode>+ <><FontPicker /><h2>Player</h2><div@@ -30,7 +30,6 @@ function Index() {}}><App component={CarSlideshow} durationInFrames={500} />- <App component={VideoautoplayDemo} durationInFrames={2700} /></div><h2>Thumbnail</h2><Thumbnail@@ -50,7 +49,7 @@ function Index() {}}/><ThumbnailDemo />- </React.StrictMode>+ </>);}diff --git a/packages/player-example/src/CarSlideshow.tsx b/packages/player-example/src/CarSlideshow.tsxindex cd4783d8e9..a9ed64869a 100644--- a/packages/player-example/src/CarSlideshow.tsx+++ b/packages/player-example/src/CarSlideshow.tsx@@ -8,6 +8,7 @@ import {staticFile,Sequence,Experimental,+ AbsoluteFill,} from 'remotion';type Props = {@@ -20,10 +21,10 @@ export const playerExampleComp = createRef<{triggerError: () => void;}>();+const show = true;+const CarSlideshow = ({title, bgColor, color}: Props) => {- const frame = useCurrentFrame();const {width, height, durationInFrames} = useVideoConfig();- const left = interpolate(frame, [0, durationInFrames], [width, width * -1]);const [shouldThrowError, setThrowError] = useState(false);@@ -57,35 +58,23 @@ const CarSlideshow = ({title, bgColor, color}: Props) => {top: 0,}}>- <Experimental.Clipper height={100} width={100} x={0} y={0} />- <h1+ <AbsoluteFillstyle={{- fontSize: '5em',- fontWeight: 'bold',- position: 'absolute',- top: height / 2 - 100,- left,- color,- whiteSpace: 'nowrap',+ width: '50%',}}>- {title} {dummyText()}- </h1>- <Img- src={staticFile('/logo.png')}- style={{- height: 40,- width: 40,- }}- />- <Sequence from={10}>- <Video+ <Video src="https://media.repliq.co/images/5PfG7Oj6LgaWgYiPCT6kiOxXMwa2/69012e32/69012e32_myScreen.mp4" />+ </AbsoluteFill>+ {show ? (+ <AbsoluteFillstyle={{- height: 200,+ left: '50%',+ width: '50%',}}- src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"- />- </Sequence>+ >+ <Video src="https://app.repliq.co/videos/videoExample1_20.mp4" />+ </AbsoluteFill>+ ) : null}</div>);};