Skip to content

🎥 Make videos programmatically with React

player icons

Jonny Burgera3b56e55777d
diff --git a/packages/player/src/PlayerControls.tsx b/packages/player/src/PlayerControls.tsx
index dd097f62e7..60b8d7e969 100644
--- a/packages/player/src/PlayerControls.tsx
+++ b/packages/player/src/PlayerControls.tsx
@@ -1,8 +1,58 @@
+import React, {useMemo} from 'react';
import {Internals} from 'remotion';
import {formatTime} from './format-time';
+import {PauseIcon, PlayIcon} from './icons';
import {PlayerSeekBar} from './PlayerSeekBar';
import {usePlaybackTime} from './PlayPause';
+const containerStyle: React.CSSProperties = {
+ boxSizing: 'border-box',
+ position: 'absolute',
+ bottom: 0,
+ width: '100%',
+ paddingTop: 40,
+ paddingBottom: 10,
+ background: 'linear-gradient(transparent, rgba(0, 0, 0, 0.4))',
+ display: 'flex',
+ paddingRight: 12,
+ paddingLeft: 12,
+ flexDirection: 'column',
+ transition: 'opacity 0.3s',
+};
+
+const buttonStyle: React.CSSProperties = {
+ appearance: 'none',
+ backgroundColor: 'transparent',
+ border: 'none',
+ cursor: 'pointer',
+ padding: 0,
+ display: 'inline',
+ marginBottom: 0,
+ height: 25,
+};
+
+const controlsRow: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'row',
+ width: '100%',
+ alignItems: 'center',
+ userSelect: 'none',
+};
+
+const xSpacer: React.CSSProperties = {
+ width: 10,
+};
+
+const ySpacer: React.CSSProperties = {
+ height: 8,
+};
+
+const timeLabel: React.CSSProperties = {
+ color: 'white',
+ fontFamily: 'sans-serif',
+ fontSize: 14,
+};
+
export const Controls: React.FC<{
fps: number;
durationInFrames: number;
@@ -12,52 +62,33 @@ export const Controls: React.FC<{
const [playing] = Internals.Timeline.usePlayingState();
const frame = Internals.Timeline.useTimelinePosition();
- // Hide if playing and mouse outside
- const shouldShow = hovered || !playing;
+ const containerCss: React.CSSProperties = useMemo(() => {
+ // Hide if playing and mouse outside
+ const shouldShow = hovered || !playing;
+ return {
+ ...containerStyle,
+ opacity: Number(shouldShow),
+ };
+ }, [hovered, playing]);
return (
- <div
- style={{
- boxSizing: 'border-box',
- position: 'absolute',
- bottom: 0,
- width: '100%',
- paddingTop: 40,
- paddingBottom: 10,
- background: 'linear-gradient(transparent, rgba(0, 0, 0, 0.4))',
- display: 'flex',
- paddingRight: 12,
- paddingLeft: 12,
- flexDirection: 'column',
- transition: 'opacity 0.3s',
- opacity: Number(shouldShow),
- }}
- >
- <div
- style={{
- display: 'flex',
- flexDirection: 'row',
- width: '100%',
- alignItems: 'center',
- userSelect: 'none',
- }}
- >
- <button type="button" onClick={toggle}>
- {playing ? 'pause' : 'play'}
- </button>
- <div style={{width: 10}} />
- <div
- style={{
- color: 'white',
- fontFamily: 'sans-serif',
- fontSize: 14,
- }}
+ <div style={containerCss}>
+ <div style={controlsRow}>
+ <button
+ type="button"
+ style={buttonStyle}
+ onClick={toggle}
+ aria-label={playing ? 'Pause video' : 'Play video'}
+ title={playing ? 'Pause video' : 'Play video'}
>
+ {playing ? <PauseIcon /> : <PlayIcon />}
+ </button>
+ <div style={xSpacer} />
+ <div style={timeLabel}>
{formatTime(frame / fps)} / {formatTime(durationInFrames / fps)}
</div>
- <div style={{flex: 1}} />
</div>
- <div style={{height: 8}} />
+ <div style={ySpacer} />
<PlayerSeekBar durationInFrames={durationInFrames} />
</div>
);
diff --git a/packages/player/src/icons.tsx b/packages/player/src/icons.tsx
new file mode 100644
index 0000000000..f27adb04d1
--- /dev/null
+++ b/packages/player/src/icons.tsx
@@ -0,0 +1,30 @@
+import React from 'react';
+
+const size = 25;
+
+export const PlayIcon: React.FC = () => {
+ return (
+ <svg
+ width={size}
+ height={size}
+ viewBox="-100 -100 400 400"
+ transform="rotate(90)"
+ >
+ <g stroke="#fff" strokeWidth="100" strokeLinejoin="round">
+ <path
+ fill="#fff"
+ d="M 2 172 a 196 100 0 0 0 195 5 A 196 240 0 0 0 100 2.259 A 196 240 0 0 0 2 172 z"
+ />
+ </g>
+ </svg>
+ );
+};
+
+export const PauseIcon: React.FC = () => {
+ return (
+ <svg viewBox="0 0 100 100" width={size} height={size}>
+ <rect x="25" y="20" width="20" height="60" fill="#fff" ry="5" rx="5" />
+ <rect x="55" y="20" width="20" height="60" fill="#fff" ry="5" rx="5" />
+ </svg>
+ );
+};