Skip to content

🎥 Make videos programmatically with React

added style(css) props support

Shankhadeep Dey01dab8fb706e
diff --git a/packages/player-example/src/App.tsx b/packages/player-example/src/App.tsx
index 8ee362fa16..13ddf1e674 100644
--- a/packages/player-example/src/App.tsx
+++ b/packages/player-example/src/App.tsx
@@ -1,15 +1,12 @@
import {Player, PlayerMethods} from '@remotion/player';
import {useRef, useState} from 'react';
import CarSlideshow from './CarSlideshow';
-import CarSlideshowNew from './CarSlideshowNew';
export default function App() {
const [title, setTitle] = useState('This is my title');
const ref = useRef<PlayerMethods>(null);
- const ref2 = useRef<PlayerMethods>(null);
-
return (
<div>
<Player
@@ -19,19 +16,11 @@ export default function App() {
fps={30}
durationInFrames={500}
component={CarSlideshow}
- controls
- props={{
- title,
+ controls={true}
+ style={{
+ position: 'relative',
+ overflow: 'hidden',
}}
- />
- <Player
- ref={ref2}
- width={768}
- height={432}
- fps={30}
- durationInFrames={500}
- component={CarSlideshowNew}
- controls
props={{
title,
}}
@@ -49,11 +38,8 @@ export default function App() {
<button type="button" onClick={() => ref.current?.pause()}>
Pause
</button>
- <button type="button" onClick={() => ref2.current?.play()}>
- Play2
- </button>
- <button type="button" onClick={() => ref2.current?.pause()}>
- Pause2
+ <button type="button" onClick={() => ref.current?.toggle()}>
+ toggle
</button>
</div>
);
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index d69761081f..12e6fcc53e 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -20,7 +20,7 @@ export type PlayerProps<T> = {
height: number;
fps: number;
controls?: boolean;
- style?: React.CSSProperties;
+ style?: Omit<React.CSSProperties, 'height' | 'width'>;
props?: T;
} & CompProps<T>;
diff --git a/packages/player/src/RootComponent.tsx b/packages/player/src/RootComponent.tsx
index 6fad4cf5dd..45431a4f34 100644
--- a/packages/player/src/RootComponent.tsx
+++ b/packages/player/src/RootComponent.tsx
@@ -4,7 +4,7 @@ import {usePlaybackTime} from './PlayPause';
const RootComponent: React.FC<{
controls: boolean;
- style?: React.CSSProperties;
+ style?: Omit<React.CSSProperties, 'width' | 'height'>;
}> = ({controls, style}) => {
const config = Internals.useUnsafeVideoConfig();
const [toggle] = usePlaybackTime();
@@ -15,25 +15,23 @@ const RootComponent: React.FC<{
return (
<Suspense fallback={<h1>Loading...</h1>}>
<div
- style={
- style
- ? style
- : {
- position: 'relative',
- width: config?.width,
- height: config?.height,
- overflow: 'hidden',
- }
- }
+ style={{
+ position: 'relative',
+ width: config?.width,
+ height: config?.height,
+ overflow: 'hidden',
+ ...style,
+ }}
>
{controls ? (
<button
type="button"
style={{
position: 'absolute',
- left: '10px',
- top: '10px',
+ left: '50%',
+ bottom: '10px',
zIndex: 100,
+ transform: 'translateX(-50%)',
}}
onClick={toggle}
>
diff --git a/packages/player/src/index.tsx b/packages/player/src/index.tsx
index 491d1f76da..bc82f0846b 100644
--- a/packages/player/src/index.tsx
+++ b/packages/player/src/index.tsx
@@ -1,6 +1,3 @@
-import {PlayerMethods} from './Player';
-
-export {Player} from './Player';
+export {Player, PlayerInstance, PlayerMethods} from './Player';
export * from './PlayPause';
export {usePlaybackTime} from './PlayPause';
-export {PlayerMethods};