Skip to content

🎥 Make videos programmatically with React

use playerwidth instead of canvas width

Jonny Burger421bf577d41a
diff --git a/packages/player/src/PlayerControls.tsx b/packages/player/src/PlayerControls.tsx
index 56c09f3426..570eef6fda 100644
--- a/packages/player/src/PlayerControls.tsx
+++ b/packages/player/src/PlayerControls.tsx
@@ -104,6 +104,7 @@ export const Controls: React.FC<{
inFrame: number | null;
outFrame: number | null;
initiallyShowControls: number | boolean;
+ playerWidth: number;
}> = ({
durationInFrames,
hovered,
@@ -120,13 +121,14 @@ export const Controls: React.FC<{
inFrame,
outFrame,
initiallyShowControls,
+ playerWidth,
}) => {
const playButtonRef = useRef<HTMLButtonElement | null>(null);
const frame = Internals.Timeline.useTimelinePosition();
const [supportsFullscreen, setSupportsFullscreen] = useState(false);
const {maxTimeLabelWidth, displayVerticalVolumeSlider} =
- useVideoControlsResize(isFullscreen, allowFullscreen);
+ useVideoControlsResize({allowFullscreen, playerWidth});
const [shouldShowInitially, setInitiallyShowControls] = useState<
boolean | number
>(() => {
diff --git a/packages/player/src/PlayerUI.tsx b/packages/player/src/PlayerUI.tsx
index d7c2009b16..40716165db 100644
--- a/packages/player/src/PlayerUI.tsx
+++ b/packages/player/src/PlayerUI.tsx
@@ -517,6 +517,7 @@ const PlayerUI: React.ForwardRefRenderFunction<
inFrame={inFrame}
outFrame={outFrame}
initiallyShowControls={initiallyShowControls}
+ playerWidth={canvasSize?.width ?? 0}
/>
) : null}
</>
diff --git a/packages/player/src/use-video-controls-resize.ts b/packages/player/src/use-video-controls-resize.ts
index 025e2731b4..528671ebf9 100644
--- a/packages/player/src/use-video-controls-resize.ts
+++ b/packages/player/src/use-video-controls-resize.ts
@@ -1,23 +1,22 @@
import {useMemo} from 'react';
-import {useVideoConfig} from 'remotion';
import {fullscreenIconSize, ICON_SIZE} from './icons';
import {VOLUME_SLIDER_WIDTH} from './MediaVolumeSlider';
import {X_PADDING, X_SPACER} from './PlayerControls';
-export const useVideoControlsResize = (
- isFullscreen: Boolean,
- allowFullScreen: Boolean
-): {
+export const useVideoControlsResize = ({
+ allowFullscreen: allowFullScreen,
+ playerWidth,
+}: {
+ allowFullscreen: boolean;
+ playerWidth: number;
+}): {
maxTimeLabelWidth: number;
- displayVerticalVolumeSlider: Boolean;
+ displayVerticalVolumeSlider: boolean;
} => {
- const {width} = useVideoConfig();
-
const resizeInfo = useMemo((): {
maxTimeLabelWidth: number;
- displayVerticalVolumeSlider: Boolean;
+ displayVerticalVolumeSlider: boolean;
} => {
- const playerWidth = isFullscreen ? window.innerWidth : width;
const playPauseIconSize = ICON_SIZE;
const volumeIconSize = ICON_SIZE;
const _fullscreenIconSize = allowFullScreen ? fullscreenIconSize : 0;
@@ -53,11 +52,12 @@ export const useVideoControlsResize = (
const displayVerticalVolumeSlider =
playerWidth < minWidthForHorizontalDisplay;
+
return {
maxTimeLabelWidth: maxTimeLabelWidthWithoutNegativeValue,
displayVerticalVolumeSlider,
};
- }, [width, isFullscreen, allowFullScreen]);
+ }, [allowFullScreen, playerWidth]);
return resizeInfo;
};