Skip to content

🎥 Make videos programmatically with React

player improvements

Jonny Burger3a739a092db5
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index a572f365da..c63481bc8f 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -46,3 +46,4 @@ export * from './use-video-config';
export * from './video';
export * from './video-config';
export {staticFile} from './static-file';
+export type {PlayableMediaTag} from './timeline-position-state';
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index 17d16cf239..4728f30224 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -20,7 +20,7 @@ import {
SetTimelineContextValue,
TimelineContextValue,
} from 'remotion';
-import {PlayableMediaTag} from 'remotion/src/timeline-position-state';
+import {PlayableMediaTag} from 'remotion';
import {PlayerEventEmitterContext} from './emitter-context';
import {PlayerEmitter} from './event-emitter';
import {PLAYER_CSS_CLASSNAME} from './player-css-classname';
@@ -64,7 +64,16 @@ Internals.CSSUtils.injectCSS(
Internals.CSSUtils.makeDefaultCSS(`.${PLAYER_CSS_CLASSNAME}`)
);
-// eslint-disable-next-line complexity
+export const componentOrNullIfLazy = <T,>(
+ props: CompProps<T>
+): LooseAnyComponent<T> | null => {
+ if ('component' in props) {
+ return props.component as LooseAnyComponent<T>;
+ }
+
+ return null;
+};
+
export const PlayerFn = <T,>(
{
durationInFrames,
@@ -103,21 +112,25 @@ export const PlayerFn = <T,>(
);
}
+ const componentForValidation = componentOrNullIfLazy(
+ componentProps
+ ) as LooseAnyComponent<unknown> | null;
+
// @ts-expect-error
- if (componentProps.component.type === Composition) {
+ if (componentForValidation?.type === Composition) {
throw new TypeError(
`'component' should not be an instance of <Composition/>. Pass the React component directly, and set the duration, fps and dimensions as separate props. See https://www.remotion.dev/docs/player/examples for an example.`
);
}
- // @ts-expect-error
- if (componentProps.component === Composition) {
+ if (componentForValidation === Composition) {
throw new TypeError(
`'component' must not be the 'Composition' component. Pass your own React component directly, and set the duration, fps and dimensions as separate props. See https://www.remotion.dev/docs/player/examples for an example.`
);
}
const component = Internals.useLazyComponent(componentProps);
+
const [frame, setFrame] = useState(0);
const [playing, setPlaying] = useState<boolean>(false);
const [rootId] = useState<string>('player-comp');