Skip to content

🎥 Make videos programmatically with React

ui tweaks

Jonny Burger7855090dffe3
diff --git a/packages/player/src/MediaVolumeSlider.tsx b/packages/player/src/MediaVolumeSlider.tsx
index 4fafa7e865..4ba2f420d2 100644
--- a/packages/player/src/MediaVolumeSlider.tsx
+++ b/packages/player/src/MediaVolumeSlider.tsx
@@ -1,12 +1,13 @@
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {Internals, interpolate} from 'remotion';
-import {VolumeOffIcon, VolumeOnIcon} from './icons';
+import {ICON_SIZE, VolumeOffIcon, VolumeOnIcon} from './icons';
import {useHoverState} from './use-hover-state';
import {useElementSize} from './utils/use-element-size';
const BAR_HEIGHT = 5;
const KNOB_SIZE = 12;
const VERTICAL_PADDING = 4;
+const VOLUME_SLIDER_WIDTH = 100;
const parentDivStyle: React.CSSProperties = {
display: 'inline-flex',
@@ -29,16 +30,19 @@ const containerStyle: React.CSSProperties = {
const barBackground: React.CSSProperties = {
height: BAR_HEIGHT,
backgroundColor: 'rgba(255, 255, 255, 0.5)',
- width: 100,
+ width: VOLUME_SLIDER_WIDTH,
borderRadius: BAR_HEIGHT / 2,
};
const getVolumeFromX = (clientX: number, width: number) => {
const pos = clientX;
- const volume = interpolate(pos, [0, width], [0, 1], {
- extrapolateLeft: 'clamp',
- extrapolateRight: 'clamp',
- });
+ const volume =
+ width === 0
+ ? 0
+ : interpolate(pos, [0, width], [0, 1], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ });
return volume;
};
@@ -46,6 +50,13 @@ const xSpacer: React.CSSProperties = {
width: 5,
};
+const volumeContainer: React.CSSProperties = {
+ display: 'inline',
+ width: ICON_SIZE,
+ height: ICON_SIZE,
+ cursor: 'pointer',
+};
+
export const MediaVolumeSlider: React.FC = () => {
const [mediaMuted, setMediaMuted] = Internals.useMediaMutedState();
const [mediaVolume, setMediaVolume] = Internals.useMediaVolumeState();
@@ -56,6 +67,8 @@ export const MediaVolumeSlider: React.FC = () => {
const size = useElementSize(currentRef);
const hover = useHoverState(parentDivRef);
+ const hoverOrDragging = hover || dragging;
+
const onClick = useCallback(() => {
setMediaMuted(!mediaMuted);
setMediaVolume(Number(mediaMuted));
@@ -116,14 +129,11 @@ export const MediaVolumeSlider: React.FC = () => {
position: 'absolute',
top: VERTICAL_PADDING - KNOB_SIZE / 2 + 5 / 2,
backgroundColor: 'white',
- left: Math.max(
- -KNOB_SIZE / 2,
- mediaVolume * (size?.width ?? 0) - KNOB_SIZE / 2
- ),
+ left: Math.max(0, mediaVolume * (size?.width ?? 0) - KNOB_SIZE / 2),
boxShadow: '0 0 2px black',
- opacity: Number(hover),
+ opacity: Number(hoverOrDragging),
};
- }, [hover, mediaVolume, size?.width]);
+ }, [hoverOrDragging, mediaVolume, size?.width]);
const fillStyle: React.CSSProperties = useMemo(() => {
return {
@@ -136,7 +146,7 @@ export const MediaVolumeSlider: React.FC = () => {
return (
<div ref={parentDivRef} style={parentDivStyle}>
- <div ref={iconDivRef} onClick={onClick}>
+ <div ref={iconDivRef} onClick={onClick} style={volumeContainer}>
{mediaMuted ? <VolumeOffIcon /> : <VolumeOnIcon />}
</div>
<div style={xSpacer} />
@@ -146,16 +156,14 @@ export const MediaVolumeSlider: React.FC = () => {
onPointerDown={onPointerDown}
style={containerStyle}
>
- {hover ? (
+ {hoverOrDragging ? (
<>
- <div style={{...barBackground}}>
+ <div style={barBackground}>
<div style={fillStyle} />
</div>
<div style={knobStyle} />
</>
- ) : (
- <div style={{width: 100}} />
- )}
+ ) : null}
</div>
</div>
);
diff --git a/packages/player/src/PlayerControls.tsx b/packages/player/src/PlayerControls.tsx
index ef553b5cbf..0fb78434dd 100644
--- a/packages/player/src/PlayerControls.tsx
+++ b/packages/player/src/PlayerControls.tsx
@@ -114,11 +114,12 @@ export const Controls: React.FC<{
{player.playing ? <PauseIcon /> : <PlayIcon />}
</button>
<div style={xSpacer} />
+ <MediaVolumeSlider />
+ <div style={xSpacer} />
<div style={timeLabel}>
{formatTime(frame / fps)} / {formatTime(durationInFrames / fps)}
</div>
<div style={xSpacer} />
- <MediaVolumeSlider />
</div>
<div style={flex1} />
{browserSupportsFullscreen && allowFullscreen ? (
diff --git a/packages/player/src/PlayerSeekBar.tsx b/packages/player/src/PlayerSeekBar.tsx
index f080d34ce4..3ac053c21b 100644
--- a/packages/player/src/PlayerSeekBar.tsx
+++ b/packages/player/src/PlayerSeekBar.tsx
@@ -138,7 +138,7 @@ export const PlayerSeekBar: React.FC<{
top: VERTICAL_PADDING - KNOB_SIZE / 2 + 5 / 2,
backgroundColor: 'white',
left: Math.max(
- -KNOB_SIZE / 2,
+ 0,
(frame / (durationInFrames - 1)) * (size?.width ?? 0) - KNOB_SIZE / 2
),
boxShadow: '0 0 2px black',
diff --git a/packages/player/src/icons.tsx b/packages/player/src/icons.tsx
index 1455377670..392545742c 100644
--- a/packages/player/src/icons.tsx
+++ b/packages/player/src/icons.tsx
@@ -1,6 +1,6 @@
import React from 'react';
-const size = 25;
+export const ICON_SIZE = 25;
const fullscreenIconSize = 16;
const rotate: React.CSSProperties = {
@@ -9,7 +9,12 @@ const rotate: React.CSSProperties = {
export const PlayIcon: React.FC = () => {
return (
- <svg width={size} height={size} viewBox="-100 -100 400 400" style={rotate}>
+ <svg
+ width={ICON_SIZE}
+ height={ICON_SIZE}
+ viewBox="-100 -100 400 400"
+ style={rotate}
+ >
<path
fill="#fff"
stroke="#fff"
@@ -23,7 +28,7 @@ export const PlayIcon: React.FC = () => {
export const PauseIcon: React.FC = () => {
return (
- <svg viewBox="0 0 100 100" width={size} height={size}>
+ <svg viewBox="0 0 100 100" width={ICON_SIZE} height={ICON_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>
@@ -90,7 +95,7 @@ export const FullscreenIcon: React.FC<{minimized: boolean}> = ({minimized}) => {
export const VolumeOffIcon: React.FC = () => {
return (
- <svg width={size} height={size} viewBox="0 0 24 24">
+ <svg width={ICON_SIZE} height={ICON_SIZE} viewBox="0 0 24 24">
<path
d="M3.63 3.63a.996.996 0 000 1.41L7.29 8.7 7 9H4c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1h3l3.29 3.29c.63.63 1.71.18 1.71-.71v-4.17l4.18 4.18c-.49.37-1.02.68-1.6.91-.36.15-.58.53-.58.92 0 .72.73 1.18 1.39.91.8-.33 1.55-.77 2.22-1.31l1.34 1.34a.996.996 0 101.41-1.41L5.05 3.63c-.39-.39-1.02-.39-1.42 0zM19 12c0 .82-.15 1.61-.41 2.34l1.53 1.53c.56-1.17.88-2.48.88-3.87 0-3.83-2.4-7.11-5.78-8.4-.59-.23-1.22.23-1.22.86v.19c0 .38.25.71.61.85C17.18 6.54 19 9.06 19 12zm-8.71-6.29l-.17.17L12 7.76V6.41c0-.89-1.08-1.33-1.71-.7zM16.5 12A4.5 4.5 0 0014 7.97v1.79l2.48 2.48c.01-.08.02-.16.02-.24z"
fill="#fff"
@@ -101,7 +106,7 @@ export const VolumeOffIcon: React.FC = () => {
export const VolumeOnIcon: React.FC = () => {
return (
- <svg width={size} height={size} viewBox="0 0 24 24">
+ <svg width={ICON_SIZE} height={ICON_SIZE} viewBox="0 0 24 24">
<path
d="M3 10v4c0 .55.45 1 1 1h3l3.29 3.29c.63.63 1.71.18 1.71-.71V6.41c0-.89-1.08-1.34-1.71-.71L7 9H4c-.55 0-1 .45-1 1zm13.5 2A4.5 4.5 0 0014 7.97v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 4.45v.2c0 .38.25.71.6.85C17.18 6.53 19 9.06 19 12s-1.82 5.47-4.4 6.5c-.36.14-.6.47-.6.85v.2c0 .63.63 1.07 1.21.85C18.6 19.11 21 15.84 21 12s-2.4-7.11-5.79-8.4c-.58-.23-1.21.22-1.21.85z"
fill="#fff"