Skip to content

🎥 Make videos programmatically with React

add testbed for buffer during a video

Jonny Burger4236bea0ba39
diff --git a/packages/example/src/NewVideoBufferState.tsx b/packages/example/src/NewVideoBufferState.tsx
new file mode 100644
index 0000000000..ba405b1a19
--- /dev/null
+++ b/packages/example/src/NewVideoBufferState.tsx
@@ -0,0 +1,71 @@
+import {Video} from '@remotion/media';
+import React, {useEffect} from 'react';
+import {Composition, Sequence, useBufferState, useCurrentFrame} from 'remotion';
+import {calculateMetadataFn} from './NewVideo';
+
+const src = 'https://remotion.media/video.mp4';
+
+const BUFFER_START_FRAME = 60;
+const BUFFER_DURATION_MS = 5000;
+
+const ForeignBufferElement: React.FC = () => {
+ const buffer = useBufferState();
+ const frame = useCurrentFrame();
+
+ useEffect(() => {
+ if (frame === BUFFER_START_FRAME) {
+ const handle = buffer.delayPlayback();
+
+ const timeout = setTimeout(() => {
+ handle.unblock();
+ }, BUFFER_DURATION_MS);
+
+ return () => {
+ clearTimeout(timeout);
+ handle.unblock();
+ };
+ }
+ }, [buffer, frame]);
+
+ return (
+ <div
+ style={{
+ position: 'absolute',
+ top: 20,
+ left: 20,
+ background: frame >= BUFFER_START_FRAME ? 'red' : 'green',
+ color: 'white',
+ padding: '8px 16px',
+ fontFamily: 'sans-serif',
+ fontSize: 14,
+ borderRadius: 4,
+ zIndex: 1000,
+ }}
+ >
+ {frame >= BUFFER_START_FRAME
+ ? `Buffering (triggered at frame ${BUFFER_START_FRAME})...`
+ : `Will buffer at frame ${BUFFER_START_FRAME} (current: ${frame})`}
+ </div>
+ );
+};
+
+const NewVideoBufferStateComponent: React.FC = () => {
+ return (
+ <>
+ <Video src={src} />
+ <Sequence>
+ <ForeignBufferElement />
+ </Sequence>
+ </>
+ );
+};
+
+export const NewVideoBufferStateComp: React.FC = () => {
+ return (
+ <Composition
+ component={NewVideoBufferStateComponent}
+ id="NewVideoBufferState"
+ calculateMetadata={calculateMetadataFn}
+ />
+ );
+};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 32dac4d060..5b14f27826 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -128,6 +128,7 @@ import {LightLeakAnimatedSize} from './LightLeak/AnimatedSize';
import {LoopDisplayTestComp} from './LoopDisplayTest';
import {NewAudioExample} from './NewAudio/NewAudio';
import {NewVideoComp} from './NewVideo';
+import {NewVideoBufferStateComp} from './NewVideoBufferState';
import {ChangingTrimBeforeValue} from './OffthreadRemoteVideo/ChangingTrimBefore';
import {LoopedNewVideo} from './OffthreadRemoteVideo/LoopedNewVideo';
import {LoopedOffthreadRemoteVideo} from './OffthreadRemoteVideo/LoopedOffthreadRemoteVideo';
@@ -788,6 +789,7 @@ export const Index: React.FC = () => {
/>
<OffthreadRemoteVideo />
<NewVideoComp />
+ <NewVideoBufferStateComp />
<LoopDisplayTestComp />
<OffthreadRemoteSeries />
<LoopedNewVideo />
@@ -1475,16 +1477,16 @@ export const Index: React.FC = () => {
defaultProps={{
title: 'sdasds',
delay: 5.2,
- color: '#df822a',
+ color: 'rgba(223, 42, 42, 0.46)',
list: [{name: 'first', age: 12}],
- matrix: [0, 1, 1, 0],
+ matrix: [0, 1, 1, 0] as const,
description: 'Sample description \nOn multiple lines',
dropdown: 'a' as const,
superSchema: [
{type: 'a' as const, a: {a: 'hi'}},
{type: 'b' as const, b: {b: 'hi'}},
],
- discriminatedUnion: {type: 'auto'},
+ discriminatedUnion: {type: 'auto' as const},
tuple: ['foo', 42, {a: 'hi'}],
}}
/>