Skip to content

🎥 Make videos programmatically with React

Prevent freezing audio (#8655)

Jonny Burger80bdcf2f1b99
diff --git a/packages/core/src/audio/html5-audio.tsx b/packages/core/src/audio/html5-audio.tsx
index 46915760d6..552c7c76b0 100644
--- a/packages/core/src/audio/html5-audio.tsx
+++ b/packages/core/src/audio/html5-audio.tsx
@@ -31,6 +31,7 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<
}
> = (props, ref) => {
const audioTagsContext = useContext(SharedAudioTagsContext);
+ const propsWithFreeze = props as typeof props & {readonly freeze?: unknown};
const {
startFrom,
endAt,
@@ -41,9 +42,10 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<
pauseWhenBuffering,
showInTimeline,
onError: onRemotionError,
+ freeze,
...otherProps
- } = props;
- const {loop, ...propsOtherThanLoop} = props;
+ } = propsWithFreeze;
+ const {loop, freeze: _freeze, ...propsOtherThanLoop} = propsWithFreeze;
const {fps} = useVideoConfig();
const environment = useRemotionEnvironment();
@@ -53,6 +55,12 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<
);
}
+ if (typeof freeze !== 'undefined') {
+ throw new TypeError(
+ 'The "freeze" prop is not supported on <Html5Audio />. Use <Sequence freeze={...}> to freeze media playback.',
+ );
+ }
+
const {durations, setDurations} = useContext(DurationsContext);
if (typeof props.src !== 'string') {
throw new TypeError(
diff --git a/packages/core/src/test/audio.test.tsx b/packages/core/src/test/audio.test.tsx
index 3d6ac040c5..68b658c95f 100644
--- a/packages/core/src/test/audio.test.tsx
+++ b/packages/core/src/test/audio.test.tsx
@@ -133,3 +133,20 @@ test('It should reject invalid preservePitch values on Audio', () => {
/'preservePitch' must be a boolean or undefined but got 'string' instead/,
);
});
+
+test('It should reject freeze on Audio', () => {
+ expect(() =>
+ render(
+ <WrapSequenceContext>
+ <Html5Audio
+ // @ts-expect-error
+ freeze={10}
+ src="test"
+ volume={1}
+ />
+ </WrapSequenceContext>,
+ ),
+ ).toThrow(
+ 'The "freeze" prop is not supported on <Html5Audio />. Use <Sequence freeze={...}> to freeze media playback.',
+ );
+});
diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsx
index f339a9f007..02f5af43e7 100644
--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx
@@ -422,7 +422,7 @@ const TimelineSequenceInner: React.FC<{
originalLocation,
selectAsset,
sequence: s,
- sourceActions: [freezeFrameMenuItem],
+ sourceActions: freezeFrameMenuItem ? [freezeFrameMenuItem] : [],
});
}, [
assetLinkInfo,
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
index 0bcc3f0da2..21cc83ce3c 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
@@ -938,7 +938,7 @@ export const TimelineSequenceItem: React.FC<{
subMenu: null,
value: 'rename-sequence',
},
- freezeFrameMenuItem,
+ ...(freezeFrameMenuItem ? [freezeFrameMenuItem] : []),
],
});
}, [
diff --git a/packages/studio/src/components/Timeline/use-sequence-freeze-frame-menu-item.ts b/packages/studio/src/components/Timeline/use-sequence-freeze-frame-menu-item.ts
index 7f7128602a..252dda98db 100644
--- a/packages/studio/src/components/Timeline/use-sequence-freeze-frame-menu-item.ts
+++ b/packages/studio/src/components/Timeline/use-sequence-freeze-frame-menu-item.ts
@@ -7,6 +7,10 @@ import type {
import type {ComboboxValue} from '../NewComposition/ComboBox';
import {saveSequenceProps, type SetPropStatuses} from './save-sequence-prop';
+export const shouldShowFreezeFrameMenuItem = (sequence: TSequence): boolean => {
+ return sequence.type !== 'audio';
+};
+
export const useSequenceFreezeFrameMenuItem = ({
clientId,
nodePath,
@@ -27,7 +31,7 @@ export const useSequenceFreezeFrameMenuItem = ({
readonly setPropStatuses: SetPropStatuses;
readonly timelinePosition: number;
readonly validatedSource: string | null;
-}): ComboboxValue => {
+}): ComboboxValue | null => {
const freezeStatus = propStatusesForOverride?.freeze;
const isFrozen =
freezeStatus?.status === 'static' &&
@@ -93,18 +97,21 @@ export const useSequenceFreezeFrameMenuItem = ({
]);
return useMemo(
- () => ({
- type: 'item' as const,
- id: 'toggle-freeze-frame',
- keyHint: null,
- label: isFrozen ? 'Unfreeze frame' : 'Freeze frame',
- leftItem: null,
- disabled: !canToggleFreeze,
- onClick: onToggleFreezeFrame,
- quickSwitcherLabel: null,
- subMenu: null,
- value: 'toggle-freeze-frame',
- }),
- [canToggleFreeze, isFrozen, onToggleFreezeFrame],
+ () =>
+ shouldShowFreezeFrameMenuItem(sequence)
+ ? {
+ type: 'item' as const,
+ id: 'toggle-freeze-frame',
+ keyHint: null,
+ label: isFrozen ? 'Unfreeze frame' : 'Freeze frame',
+ leftItem: null,
+ disabled: !canToggleFreeze,
+ onClick: onToggleFreezeFrame,
+ quickSwitcherLabel: null,
+ subMenu: null,
+ value: 'toggle-freeze-frame',
+ }
+ : null,
+ [canToggleFreeze, isFrozen, onToggleFreezeFrame, sequence],
);
};
diff --git a/packages/studio/src/test/sequence-context-menu-items.test.ts b/packages/studio/src/test/sequence-context-menu-items.test.ts
index edefd68df6..0b2b9f0d11 100644
--- a/packages/studio/src/test/sequence-context-menu-items.test.ts
+++ b/packages/studio/src/test/sequence-context-menu-items.test.ts
@@ -2,6 +2,7 @@ import {afterEach, expect, test} from 'bun:test';
import type {TSequence} from 'remotion';
import type {ComboboxValue} from '../components/NewComposition/ComboBox';
import {getSequenceContextMenuItems} from '../components/Timeline/get-sequence-context-menu-items';
+import {shouldShowFreezeFrameMenuItem} from '../components/Timeline/use-sequence-freeze-frame-menu-item';
const originalWindowDescriptor = Object.getOwnPropertyDescriptor(
globalThis,
@@ -90,3 +91,15 @@ test('sequence context menu does not put two dividers between docs and rename',
items.slice(docsIndex + 1, renameIndex).map((item) => item.type),
).toEqual(['divider']);
});
+
+test('sequence freeze context menu item is hidden for audio', () => {
+ expect(shouldShowFreezeFrameMenuItem({type: 'audio'} as TSequence)).toBe(
+ false,
+ );
+ expect(shouldShowFreezeFrameMenuItem({type: 'video'} as TSequence)).toBe(
+ true,
+ );
+ expect(shouldShowFreezeFrameMenuItem({type: 'sequence'} as TSequence)).toBe(
+ true,
+ );
+});