Skip to content

🎥 Make videos programmatically with React

mobile improvements

umungobungoe08254d89dda
diff --git a/packages/docs/src/components/Demo/PlayPauseButton.tsx b/packages/docs/src/components/Demo/PlayPauseButton.tsx
new file mode 100644
index 0000000000..d9ba7e8fe6
--- /dev/null
+++ b/packages/docs/src/components/Demo/PlayPauseButton.tsx
@@ -0,0 +1,63 @@
+import type {PlayerRef} from '@remotion/player';
+import React, {useCallback, useEffect} from 'react';
+import {BlueButton} from '../../../components/layout/Button';
+import {PausedIcon, PlayingIcon} from '../../icons/arrows';
+
+const playerButtonStyle: React.CSSProperties = {
+ width: '40px',
+ height: '40px',
+ padding: 0,
+};
+
+export const PlayPauseButton: React.FC<{
+ playerRef: React.RefObject<PlayerRef>;
+}> = ({playerRef}) => {
+ const [playing, setPlaying] = React.useState(true);
+
+ useEffect(() => {
+ const {current} = playerRef;
+ if (!current) {
+ return;
+ }
+
+ const onPlay = () => {
+ setPlaying(true);
+ };
+
+ const onPause = () => {
+ setPlaying(false);
+ };
+
+ current.addEventListener('play', onPlay);
+ current.addEventListener('pause', onPause);
+
+ return () => {
+ current.removeEventListener('play', onPlay);
+ current.removeEventListener('pause', onPause);
+ };
+ }, [playerRef]);
+
+ const onToggle = useCallback(() => {
+ playerRef.current?.toggle();
+ }, [playerRef]);
+
+ const playPauseIconStyle: React.CSSProperties = {
+ width: 15,
+ };
+
+ return (
+ <BlueButton
+ size="bg"
+ fullWidth={false}
+ loading={false}
+ style={playerButtonStyle}
+ onClick={onToggle}
+ >
+ {playing ? (
+ <PlayingIcon style={playPauseIconStyle} />
+ ) : (
+ <PausedIcon style={playPauseIconStyle} />
+ )}
+ </BlueButton>
+ );
+};
diff --git a/packages/docs/src/components/Demo/PlayerButton.tsx b/packages/docs/src/components/Demo/PlayerButton.tsx
deleted file mode 100644
index 5bd6de4973..0000000000
--- a/packages/docs/src/components/Demo/PlayerButton.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import React, {type ButtonHTMLAttributes, type DetailedHTMLProps} from 'react';
-import {BlueButton} from '../../../components/layout/Button';
-
-const playerButtonStyle: React.CSSProperties = {
- width: '40px',
- height: '40px',
- padding: 0,
- background: 'var(--blue-underlay)',
- color: 'white',
-};
-
-export const PlayerButton: React.FC<
- DetailedHTMLProps<
- ButtonHTMLAttributes<HTMLButtonElement>,
- HTMLButtonElement
- > & {
- children: React.ReactNode;
- }
-> = ({children, ...props}) => {
- return (
- <BlueButton
- size="bg"
- fullWidth={false}
- loading={false}
- style={playerButtonStyle}
- {...props}
- >
- {children}
- </BlueButton>
- );
-};
diff --git a/packages/docs/src/components/Demo/PlayerControls.tsx b/packages/docs/src/components/Demo/PlayerControls.tsx
index 2c13fcfac9..276ad63cdf 100644
--- a/packages/docs/src/components/Demo/PlayerControls.tsx
+++ b/packages/docs/src/components/Demo/PlayerControls.tsx
@@ -1,10 +1,10 @@
import type {PlayerRef} from '@remotion/player';
-import React, {useCallback, useEffect} from 'react';
-import {PausedIcon, PlayingIcon} from '../../icons/arrows';
-import {PlayerButton} from './PlayerButton';
+import React, {useEffect} from 'react';
+import styles from './player.module.css';
import {PlayerFullscreen} from './PlayerFullscreen';
import {PlayerSeekBar} from './PlayerSeekBar';
import {PlayerVolume} from './PlayerVolume';
+import {PlayPauseButton} from './PlayPauseButton';
const formatTime = (timeInSeconds: number) => {
const minutes = Math.floor(timeInSeconds / 60);
@@ -12,53 +12,6 @@ const formatTime = (timeInSeconds: number) => {
return `${String(minutes)}:${String(seconds).padStart(2, '0')}`;
};
-const PlayButton: React.FC<{
- playerRef: React.RefObject<PlayerRef>;
-}> = ({playerRef}) => {
- const [playing, setPlaying] = React.useState(true);
-
- useEffect(() => {
- const {current} = playerRef;
- if (!current) {
- return;
- }
-
- const onPlay = () => {
- setPlaying(true);
- };
-
- const onPause = () => {
- setPlaying(false);
- };
-
- current.addEventListener('play', onPlay);
- current.addEventListener('pause', onPause);
-
- return () => {
- current.removeEventListener('play', onPlay);
- current.removeEventListener('pause', onPause);
- };
- }, [playerRef]);
-
- const onToggle = useCallback(() => {
- playerRef.current?.toggle();
- }, [playerRef]);
-
- const playPauseIconStyle: React.CSSProperties = {
- width: 15,
- };
-
- return (
- <PlayerButton onClick={onToggle}>
- {playing ? (
- <PlayingIcon style={playPauseIconStyle} />
- ) : (
- <PausedIcon style={playPauseIconStyle} />
- )}
- </PlayerButton>
- );
-};
-
const TimeDisplay: React.FC<{
durationInFrames: number;
fps: number;
@@ -99,40 +52,15 @@ const TimeDisplay: React.FC<{
);
};
-const row: React.CSSProperties = {
- display: 'flex',
- flexDirection: 'row',
- alignItems: 'center',
- marginTop: '1rem',
- padding: '5px 0px',
- borderRadius: '0.5rem',
- gap: '20px',
-};
-
-const startControls: React.CSSProperties = {
- display: 'flex',
- flexDirection: 'row',
- alignItems: 'center',
- gap: '10px',
- width: '100%',
-};
-
-const endControls: React.CSSProperties = {
- display: 'flex',
- flexDirection: 'row',
- alignItems: 'center',
- gap: '20px',
-};
-
export const PlayerControls: React.FC<{
playerRef: React.RefObject<PlayerRef>;
durationInFrames: number;
fps: number;
}> = ({playerRef, durationInFrames, fps}) => {
return (
- <div style={row}>
- <div style={startControls}>
- <PlayButton playerRef={playerRef} />
+ <div className={styles['controls-wrapper']}>
+ <div className={styles['start-controls']}>
+ <PlayPauseButton playerRef={playerRef} />
<div style={{flex: 1}}>
<PlayerSeekBar
durationInFrames={durationInFrames}
@@ -149,7 +77,7 @@ export const PlayerControls: React.FC<{
fps={fps}
/>
</div>
- <div style={endControls}>
+ <div className={styles['end-controls']}>
<PlayerVolume playerRef={playerRef} />
<PlayerFullscreen playerRef={playerRef} />
</div>
diff --git a/packages/docs/src/components/Demo/player.module.css b/packages/docs/src/components/Demo/player.module.css
new file mode 100644
index 0000000000..1c20fa380c
--- /dev/null
+++ b/packages/docs/src/components/Demo/player.module.css
@@ -0,0 +1,43 @@
+.controls-wrapper {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ padding: 5px 0px;
+ border-radius: 0.5rem;
+
+ .start-controls {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ gap: 10px;
+ width: 100%;
+ }
+
+ .end-controls {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ }
+}
+
+@media screen and (max-width: 900px) {
+ .controls-wrapper {
+ margin-top: 0.5rem;
+ gap: 15px;
+ }
+
+ .end-controls {
+ gap: 15px;
+ }
+}
+
+@media screen and (min-width: 901px) {
+ .controls-wrapper {
+ margin-top: 1rem;
+ gap: 20px;
+ }
+
+ .end-controls {
+ gap: 20px;
+ }
+}