Skip to content

πŸŽ₯ Make videos programmatically with React

play/volume/fullscreen looking nice

umungobungo8bfd5656a7dd
diff --git a/packages/docs/components/Player/Footer.tsx b/packages/docs/components/Player/Footer.tsx
index 60ec6809c2..e5ee838dbe 100644
--- a/packages/docs/components/Player/Footer.tsx
+++ b/packages/docs/components/Player/Footer.tsx
@@ -1,70 +1,70 @@
-import React from "react";
-import { BlueButton } from "../layout/Button";
-import styles from "./footer.module.css";
+import React from 'react';
+import {BlueButton} from '../layout/Button';
+import styles from './footer.module.css';
const container: React.CSSProperties = {
- maxWidth: 1000,
- paddingLeft: 16,
- paddingRight: 16,
- margin: "auto",
+ maxWidth: 1000,
+ paddingLeft: 16,
+ paddingRight: 16,
+ margin: 'auto',
};
const half: React.CSSProperties = {
- display: "flex",
- flex: 1,
- flexDirection: "row",
+ display: 'flex',
+ flex: 1,
+ flexDirection: 'row',
};
const inner: React.CSSProperties = {
- textAlign: "center",
- display: "flex",
- flexDirection: "column",
- padding: 16,
- paddingTop: 80,
- borderRadius: 10,
- flex: 1,
- backgroundColor: "var(--background)",
- width: "100%",
+ textAlign: 'center',
+ display: 'flex',
+ flexDirection: 'column',
+ padding: 16,
+ paddingTop: 80,
+ borderRadius: 10,
+ flex: 1,
+ backgroundColor: 'var(--background)',
+ width: '100%',
};
export const PlayerPageFooter: React.FC = () => {
- return (
- <div
- style={{ backgroundColor: "#0B84F3", paddingTop: 20, paddingBottom: 20 }}
- >
- <div className={styles.footerrow} style={container}>
- <div
- style={{
- ...half,
- justifyContent: "flex-end",
- }}
- >
- <div style={inner}>
- <h2 className={styles.title}>New to Remotion?</h2>
- <p>Learn about how to make videos in React.</p>
- <div style={{ height: 100 }} />
+ return (
+ <div
+ style={{backgroundColor: '#0B84F3', paddingTop: 20, paddingBottom: 20}}
+ >
+ <div className={styles.footerrow} style={container}>
+ <div
+ style={{
+ ...half,
+ justifyContent: 'flex-end',
+ }}
+ >
+ <div style={inner}>
+ <h2 className={styles.title}>New to Remotion?</h2>
+ <p>Learn about how to make videos in React.</p>
+ <div style={{height: 100}} />
- <a href="/" style={{ textDecoration: "none" }}>
- <BlueButton loading={false} fullWidth size="sm">
- Learn Remotion
- </BlueButton>
- </a>
- </div>
- </div>
- <div style={{ width: 20, height: 20 }} />
- <div style={{ ...half, backgroundColor: "#0B84F3" }}>
- <div style={inner}>
- <h2 className={styles.title}>Already used Remotion?</h2>
- <p>Let{"'"}s get setup with the Player.</p>
- <div style={{ height: 100 }} />
- <a href="/docs/player" style={{ textDecoration: "none" }}>
- <BlueButton loading={false} fullWidth size="sm">
- Installation
- </BlueButton>
- </a>
- </div>
- </div>
- </div>
- </div>
- );
+ <a href="/" style={{textDecoration: 'none'}}>
+ <BlueButton loading={false} fullWidth size="sm">
+ Learn Remotion
+ </BlueButton>
+ </a>
+ </div>
+ </div>
+ <div style={{width: 20, height: 20}} />
+ <div style={{...half, backgroundColor: '#0B84F3'}}>
+ <div style={inner}>
+ <h2 className={styles.title}>Already used Remotion?</h2>
+ <p>Let{"'"}s get setup with the Player.</p>
+ <div style={{height: 100}} />
+ <a href="/docs/player" style={{textDecoration: 'none'}}>
+ <BlueButton loading={false} fullWidth size="sm">
+ Installation
+ </BlueButton>
+ </a>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
};
diff --git a/packages/docs/components/layout/Button.tsx b/packages/docs/components/layout/Button.tsx
index bab9366ded..dfae5a3026 100644
--- a/packages/docs/components/layout/Button.tsx
+++ b/packages/docs/components/layout/Button.tsx
@@ -1,92 +1,94 @@
-import { opacify } from "polished";
-import type { ButtonHTMLAttributes, DetailedHTMLProps } from "react";
-import React from "react";
-import styles from "./button.module.css";
-import { RED, UNDERLAY_RED } from "./colors";
+import {opacify} from 'polished';
+import type {ButtonHTMLAttributes, DetailedHTMLProps} from 'react';
+import React from 'react';
+import styles from './button.module.css';
+import {RED, UNDERLAY_RED} from './colors';
type ExtraProps = {
- size: Size;
- fullWidth: boolean;
- background: string;
- hoverColor?: string;
- color: string;
- loading: boolean;
+ size: Size;
+ fullWidth: boolean;
+ background: string;
+ hoverColor?: string;
+ color: string;
+ loading: boolean;
};
-type Size = "sm" | "bg";
+type Size = 'sm' | 'bg';
type Props = DetailedHTMLProps<
- ButtonHTMLAttributes<HTMLButtonElement>,
- HTMLButtonElement
+ ButtonHTMLAttributes<HTMLButtonElement>,
+ HTMLButtonElement
> &
- ExtraProps;
-type MandatoryProps = Omit<ExtraProps, "background" | "color" | "hoverColor">;
+ ExtraProps;
+type MandatoryProps = Omit<ExtraProps, 'background' | 'color' | 'hoverColor'>;
type PrestyledProps = DetailedHTMLProps<
- ButtonHTMLAttributes<HTMLButtonElement>,
- HTMLButtonElement
+ ButtonHTMLAttributes<HTMLButtonElement>,
+ HTMLButtonElement
> &
- MandatoryProps;
+ MandatoryProps;
export const Button: React.FC<Props> = (props) => {
- const { children, loading, hoverColor, fullWidth, color, size, ...other } =
- props;
- const actualDisabled = other.disabled || loading;
+ const {children, loading, hoverColor, fullWidth, color, size, ...other} =
+ props;
+ const actualDisabled = other.disabled || loading;
- return (
- <button
- type="button"
- className={styles.buttoncontainer}
- disabled={actualDisabled}
- {...other}
- style={{
- ...(props.style ?? {}),
- padding: props.size === "sm" ? "10px 16px" : "16px 22px",
- color: props.color,
- cursor: props.disabled ? "default" : "pointer",
- backgroundColor: props.background,
- // @ts-expect-error
- "--hover-color": props.hoverColor ?? props.background,
- ...(props.fullWidth ? { width: "100%" } : {}),
- opacity: props.disabled ? 0.7 : 1,
- }}
- >
- {children}
- </button>
- );
+ return (
+ <button
+ type="button"
+ className={styles.buttoncontainer}
+ disabled={actualDisabled}
+ {...other}
+ style={{
+ ...(props.style ?? {}),
+ padding:
+ props.style?.padding ??
+ (props.size === 'sm' ? '10px 16px' : '16px 22px'),
+ color: props.color,
+ cursor: props.disabled ? 'default' : 'pointer',
+ backgroundColor: props.background,
+ // @ts-expect-error
+ '--hover-color': props.hoverColor ?? props.background,
+ ...(props.fullWidth ? {width: '100%'} : {}),
+ opacity: props.disabled ? 0.7 : 1,
+ }}
+ >
+ {children}
+ </button>
+ );
};
export const BlueButton: React.FC<PrestyledProps> = (props) => {
- return <Button {...props} background="var(--blue-underlay)" color="white" />;
+ return <Button {...props} background="var(--blue-underlay)" color="white" />;
};
export const PlainButton: React.FC<PrestyledProps> = (props) => {
- return (
- <Button
- {...props}
- background="var(--plain-button)"
- color="var(--text-color)"
- />
- );
+ return (
+ <Button
+ {...props}
+ background="var(--plain-button)"
+ color="var(--text-color)"
+ />
+ );
};
export const RedButton: React.FC<PrestyledProps> = (props) => {
- return (
- <Button
- {...props}
- background={UNDERLAY_RED}
- hoverColor={opacify(0.1, UNDERLAY_RED)}
- color={RED}
- />
- );
+ return (
+ <Button
+ {...props}
+ background={UNDERLAY_RED}
+ hoverColor={opacify(0.1, UNDERLAY_RED)}
+ color={RED}
+ />
+ );
};
export const ClearButton: React.FC<PrestyledProps> = (props) => {
- return (
- <Button
- {...props}
- background="transparent"
- color="var(--text-color)"
- hoverColor="var(--clear-hover)"
- />
- );
+ return (
+ <Button
+ {...props}
+ background="transparent"
+ color="var(--text-color)"
+ hoverColor="var(--clear-hover)"
+ />
+ );
};
diff --git a/packages/docs/src/components/Demo/Demo.tsx b/packages/docs/src/components/Demo/Demo.tsx
index 9e207d0228..e9509e9bc8 100644
--- a/packages/docs/src/components/Demo/Demo.tsx
+++ b/packages/docs/src/components/Demo/Demo.tsx
@@ -41,7 +41,6 @@ export const Demo: React.FC = () => {
playerRef.removeEventListener('fullscreenchange', onFullscreenChange);
};
}, [data]);
- console.log({isFullscreen});
return (
<div>
diff --git a/packages/docs/src/components/Demo/PlayerButton.tsx b/packages/docs/src/components/Demo/PlayerButton.tsx
new file mode 100644
index 0000000000..5bd6de4973
--- /dev/null
+++ b/packages/docs/src/components/Demo/PlayerButton.tsx
@@ -0,0 +1,31 @@
+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 55759aea41..2c13fcfac9 100644
--- a/packages/docs/src/components/Demo/PlayerControls.tsx
+++ b/packages/docs/src/components/Demo/PlayerControls.tsx
@@ -1,7 +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 {PlayerFullscreen} from './PlayerFullscreen';
import {PlayerSeekBar} from './PlayerSeekBar';
+import {PlayerVolume} from './PlayerVolume';
const formatTime = (timeInSeconds: number) => {
const minutes = Math.floor(timeInSeconds / 60);
@@ -41,10 +44,18 @@ const PlayButton: React.FC<{
playerRef.current?.toggle();
}, [playerRef]);
+ const playPauseIconStyle: React.CSSProperties = {
+ width: 15,
+ };
+
return (
- <button type="button" onClick={onToggle}>
- {playing ? '❚❚' : 'β–Ά'}
- </button>
+ <PlayerButton onClick={onToggle}>
+ {playing ? (
+ <PlayingIcon style={playPauseIconStyle} />
+ ) : (
+ <PausedIcon style={playPauseIconStyle} />
+ )}
+ </PlayerButton>
);
};
@@ -73,8 +84,17 @@ const TimeDisplay: React.FC<{
}, [playerRef]);
return (
- <div>
- {formatTime(time / fps)} / {formatTime(durationInFrames / fps)}
+ <div
+ style={{
+ fontFamily: 'monospace',
+ fontSize: '14px',
+ display: 'flex',
+ gap: '8px',
+ }}
+ >
+ <span>{formatTime(time / fps)}</span>
+ <span style={{opacity: 0.6}}>/</span>
+ <span style={{opacity: 0.6}}>{formatTime(durationInFrames / fps)}</span>
</div>
);
};
@@ -82,6 +102,26 @@ 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<{
@@ -91,23 +131,28 @@ export const PlayerControls: React.FC<{
}> = ({playerRef, durationInFrames, fps}) => {
return (
<div style={row}>
- <PlayButton playerRef={playerRef} />
- <TimeDisplay
- playerRef={playerRef}
- durationInFrames={durationInFrames}
- fps={fps}
- />
- <div style={{flex: 1}}>
- <PlayerSeekBar
- durationInFrames={durationInFrames}
+ <div style={startControls}>
+ <PlayButton playerRef={playerRef} />
+ <div style={{flex: 1}}>
+ <PlayerSeekBar
+ durationInFrames={durationInFrames}
+ playerRef={playerRef}
+ inFrame={null}
+ outFrame={null}
+ onSeekEnd={() => undefined}
+ onSeekStart={() => undefined}
+ />
+ </div>
+ <TimeDisplay
playerRef={playerRef}
- inFrame={null}
- outFrame={null}
- onSeekEnd={() => undefined}
- onSeekStart={() => undefined}
+ durationInFrames={durationInFrames}
+ fps={fps}
/>
</div>
- <PlayerFullscreen playerRef={playerRef} />
+ <div style={endControls}>
+ <PlayerVolume playerRef={playerRef} />
+ <PlayerFullscreen playerRef={playerRef} />
+ </div>
</div>
);
};
diff --git a/packages/docs/src/components/Demo/PlayerFullscreen.tsx b/packages/docs/src/components/Demo/PlayerFullscreen.tsx
index 1dfc72d662..b0647757b6 100644
--- a/packages/docs/src/components/Demo/PlayerFullscreen.tsx
+++ b/packages/docs/src/components/Demo/PlayerFullscreen.tsx
@@ -1,5 +1,6 @@
import type {PlayerRef} from '@remotion/player';
import React, {useCallback, useEffect, useState} from 'react';
+import {FullscreenIcon} from '../../icons/arrows';
export const PlayerFullscreen: React.FC<{
playerRef: React.RefObject<PlayerRef>;
@@ -49,8 +50,17 @@ export const PlayerFullscreen: React.FC<{
}
return (
- <button type="button" onClick={onClick}>
- {isFullscreen ? 'βœ”οΈ' : '❌'}
+ <button
+ type="button"
+ onClick={onClick}
+ style={{
+ background: 'transparent',
+ border: 0,
+ cursor: 'pointer',
+ padding: 0,
+ }}
+ >
+ <FullscreenIcon style={{width: 20}} />
</button>
);
};
diff --git a/packages/docs/src/components/Demo/PlayerVolume.tsx b/packages/docs/src/components/Demo/PlayerVolume.tsx
new file mode 100644
index 0000000000..7281b16e79
--- /dev/null
+++ b/packages/docs/src/components/Demo/PlayerVolume.tsx
@@ -0,0 +1,53 @@
+import type {PlayerRef} from '@remotion/player';
+import React, {useCallback, useEffect, useState} from 'react';
+import {IsMutedIcon, NotMutedIcon} from '../../icons/arrows';
+
+export const PlayerVolume: React.FC<{
+ playerRef: React.RefObject<PlayerRef>;
+}> = ({playerRef}) => {
+ const [isMuted, setIsMuted] = useState(false);
+
+ useEffect(() => {
+ const {current} = playerRef;
+
+ if (!current) {
+ return;
+ }
+
+ const onMutedChange = (e) => {
+ setIsMuted(e.detail.isMuted);
+ };
+
+ current.addEventListener('mutechange', onMutedChange);
+
+ return () => {
+ current.removeEventListener('mutechange', onMutedChange);
+ };
+ }, [playerRef]);
+
+ const onClick = useCallback(() => {
+ if (isMuted) {
+ playerRef.current.unmute();
+ } else {
+ playerRef.current.mute();
+ }
+ }, [isMuted, playerRef]);
+ return (
+ <button
+ type="button"
+ onClick={onClick}
+ style={{
+ background: 'transparent',
+ border: 0,
+ cursor: 'pointer',
+ padding: 0,
+ }}
+ >
+ {isMuted ? (
+ <IsMutedIcon style={{width: 20, opacity: 0.3}} />
+ ) : (
+ <NotMutedIcon style={{width: 20}} />
+ )}{' '}
+ </button>
+ );
+};
diff --git a/packages/docs/src/icons/arrows.tsx b/packages/docs/src/icons/arrows.tsx
index e5b3a4087e..d66910c260 100644
--- a/packages/docs/src/icons/arrows.tsx
+++ b/packages/docs/src/icons/arrows.tsx
@@ -59,3 +59,55 @@ export const PausedIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
</svg>
);
};
+
+export const PlayingIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 320 512"
+ fill="currentColor"
+ {...props}
+ >
+ <path d="M48 64C21.5 64 0 85.5 0 112L0 400c0 26.5 21.5 48 48 48l32 0c26.5 0 48-21.5 48-48l0-288c0-26.5-21.5-48-48-48L48 64zm192 0c-26.5 0-48 21.5-48 48l0 288c0 26.5 21.5 48 48 48l32 0c26.5 0 48-21.5 48-48l0-288c0-26.5-21.5-48-48-48l-32 0z" />
+ </svg>
+ );
+};
+
+export const FullscreenIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 448 512"
+ fill="currentColor"
+ {...props}
+ >
+ <path d="M32 32C14.3 32 0 46.3 0 64l0 96c0 17.7 14.3 32 32 32s32-14.3 32-32l0-64 64 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 32zM64 352c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 96c0 17.7 14.3 32 32 32l96 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-64 0 0-64zM320 32c-17.7 0-32 14.3-32 32s14.3 32 32 32l64 0 0 64c0 17.7 14.3 32 32 32s32-14.3 32-32l0-96c0-17.7-14.3-32-32-32l-96 0zM448 352c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 64-64 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l96 0c17.7 0 32-14.3 32-32l0-96z" />
+ </svg>
+ );
+};
+
+export const NotMutedIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 640 512"
+ fill="currentColor"
+ {...props}
+ >
+ <path d="M533.6 32.5C598.5 85.2 640 165.8 640 256s-41.5 170.7-106.4 223.5c-10.3 8.4-25.4 6.8-33.8-3.5s-6.8-25.4 3.5-33.8C557.5 398.2 592 331.2 592 256s-34.5-142.2-88.7-186.3c-10.3-8.4-11.8-23.5-3.5-33.8s23.5-11.8 33.8-3.5zM473.1 107c43.2 35.2 70.9 88.9 70.9 149s-27.7 113.8-70.9 149c-10.3 8.4-25.4 6.8-33.8-3.5s-6.8-25.4 3.5-33.8C475.3 341.3 496 301.1 496 256s-20.7-85.3-53.2-111.8c-10.3-8.4-11.8-23.5-3.5-33.8s23.5-11.8 33.8-3.5zm-60.5 74.5C434.1 199.1 448 225.9 448 256s-13.9 56.9-35.4 74.5c-10.3 8.4-25.4 6.8-33.8-3.5s-6.8-25.4 3.5-33.8C393.1 284.4 400 271 400 256s-6.9-28.4-17.7-37.3c-10.3-8.4-11.8-23.5-3.5-33.8s23.5-11.8 33.8-3.5zM301.1 34.8C312.6 40 320 51.4 320 64l0 384c0 12.6-7.4 24-18.9 29.2s-25 3.1-34.4-5.3L131.8 352 64 352c-35.3 0-64-28.7-64-64l0-64c0-35.3 28.7-64 64-64l67.8 0L266.7 40.1c9.4-8.4 22.9-10.4 34.4-5.3z" />
+ </svg>
+ );
+};
+
+export const IsMutedIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 640 512"
+ fill="currentColor"
+ {...props}
+ >
+ <path d="M320 64c0-12.6-7.4-24-18.9-29.2s-25-3.1-34.4 5.3L131.8 160 64 160c-35.3 0-64 28.7-64 64l0 64c0 35.3 28.7 64 64 64l67.8 0L266.7 471.9c9.4 8.4 22.9 10.4 34.4 5.3S320 460.6 320 448l0-384z" />
+ </svg>
+ );
+};