Skip to content

🎥 Make videos programmatically with React

simplify media validation

Jonny Burger95b3008d77d4
diff --git a/packages/core/src/audio/Audio.tsx b/packages/core/src/audio/Audio.tsx
index 5443830cb2..9cda3e4a7a 100644
--- a/packages/core/src/audio/Audio.tsx
+++ b/packages/core/src/audio/Audio.tsx
@@ -1,5 +1,6 @@
import React from 'react';
import {Sequence} from '../sequencing';
+import {validateMediaProps} from '../validate-media-props';
import {validateStartFromProps} from '../validate-start-from-props';
import {AudioForDevelopment} from './AudioForDevelopment';
import {AudioForRendering} from './AudioForRendering';
@@ -19,6 +20,8 @@ export const Audio: React.FC<RemotionAudioProps & RemotionMainAudioProps> = (
</Sequence>
);
}
+ validateMediaProps(props, 'Audio');
+
if (process.env.NODE_ENV === 'development') {
return <AudioForDevelopment {...props} />;
}
diff --git a/packages/core/src/audio/AudioForDevelopment.tsx b/packages/core/src/audio/AudioForDevelopment.tsx
index b374927e3a..7d9ac1afef 100644
--- a/packages/core/src/audio/AudioForDevelopment.tsx
+++ b/packages/core/src/audio/AudioForDevelopment.tsx
@@ -6,7 +6,6 @@ import {SequenceContext} from '../sequencing';
import {TimelineContext, usePlayingState} from '../timeline-position-state';
import {useAbsoluteCurrentFrame, useCurrentFrame} from '../use-frame';
import {useUnsafeVideoConfig} from '../use-unsafe-video-config';
-import {validateMediaProps} from '../validate-media-props';
import {RemotionAudioProps} from './props';
export const AudioForDevelopment: React.FC<RemotionAudioProps> = (props) => {
@@ -26,8 +25,6 @@ export const AudioForDevelopment: React.FC<RemotionAudioProps> = (props) => {
const [id] = useState(() => String(Math.random()));
- validateMediaProps(props, 'Audio');
-
const {volume, ...nativeProps} = props;
useEffect(() => {
diff --git a/packages/core/src/audio/AudioForRendering.tsx b/packages/core/src/audio/AudioForRendering.tsx
index b96f2e7399..a356ff452f 100644
--- a/packages/core/src/audio/AudioForRendering.tsx
+++ b/packages/core/src/audio/AudioForRendering.tsx
@@ -3,7 +3,6 @@ import {CompositionManager} from '../CompositionManager';
import {random} from '../random';
import {SequenceContext} from '../sequencing';
import {useAbsoluteCurrentFrame, useCurrentFrame} from '../use-frame';
-import {validateMediaProps} from '../validate-media-props';
import {RemotionAudioProps} from './props';
export const AudioForRendering: React.FC<RemotionAudioProps> = (props) => {
@@ -12,8 +11,6 @@ export const AudioForRendering: React.FC<RemotionAudioProps> = (props) => {
const sequenceContext = useContext(SequenceContext);
const {registerAsset, unregisterAsset} = useContext(CompositionManager);
- validateMediaProps(props, 'Audio');
-
// Generate a string that's as unique as possible for this asset
// but at the same time the same on all threads
const id = useMemo(
diff --git a/packages/core/src/video/Video.tsx b/packages/core/src/video/Video.tsx
index b9c5781534..6d4ecfafe2 100644
--- a/packages/core/src/video/Video.tsx
+++ b/packages/core/src/video/Video.tsx
@@ -1,5 +1,6 @@
import React from 'react';
import {Sequence} from '../sequencing';
+import {validateMediaProps} from '../validate-media-props';
import {validateStartFromProps} from '../validate-start-from-props';
import {RemotionMainVideoProps, RemotionVideoProps} from './props';
import {VideoForDevelopment} from './VideoForDevelopment';
@@ -20,6 +21,7 @@ export const Video: React.FC<RemotionVideoProps & RemotionMainVideoProps> = (
</Sequence>
);
}
+ validateMediaProps(props, 'Video');
if (process.env.NODE_ENV === 'development') {
return <VideoForDevelopment {...props} />;
diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsx
index 0e29663368..bcf5eaf20f 100644
--- a/packages/core/src/video/VideoForDevelopment.tsx
+++ b/packages/core/src/video/VideoForDevelopment.tsx
@@ -3,7 +3,6 @@ import {FEATURE_FLAG_V2_BREAKING_CHANGES} from '../feature-flags';
import {usePlayingState} from '../timeline-position-state';
import {useAbsoluteCurrentFrame, useCurrentFrame} from '../use-frame';
import {useUnsafeVideoConfig} from '../use-unsafe-video-config';
-import {validateMediaProps} from '../validate-media-props';
import {RemotionVideoProps} from './props';
export const VideoForDevelopment: React.FC<RemotionVideoProps> = (props) => {
@@ -15,8 +14,6 @@ export const VideoForDevelopment: React.FC<RemotionVideoProps> = (props) => {
const {volume, ...nativeProps} = props;
- validateMediaProps(props, 'Video');
-
// TODO: Register as an asset
useEffect(() => {
if (playing && !videoRef.current?.ended) {
diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsx
index cf424162c5..f40af65e6b 100644
--- a/packages/core/src/video/VideoForRendering.tsx
+++ b/packages/core/src/video/VideoForRendering.tsx
@@ -7,7 +7,6 @@ import {continueRender, delayRender} from '../ready-manager';
import {SequenceContext} from '../sequencing';
import {useCurrentFrame} from '../use-frame';
import {useUnsafeVideoConfig} from '../use-unsafe-video-config';
-import {validateMediaProps} from '../validate-media-props';
import {RemotionVideoProps} from './props';
export const VideoForRendering: React.FC<RemotionVideoProps> = ({
@@ -21,8 +20,6 @@ export const VideoForRendering: React.FC<RemotionVideoProps> = ({
const {registerAsset, unregisterAsset} = useContext(CompositionManager);
- validateMediaProps(props, 'Video');
-
// Generate a string that's as unique as possible for this asset
// but at the same time the same on all threads
const id = useMemo(