Skip to content

🎥 Make videos programmatically with React

Docs: Revert transition hover fix, use initiallyMuted

Jonny Burgeraf39a72be028
diff --git a/packages/docs/components/transitions/previews.tsx b/packages/docs/components/transitions/previews.tsx
index 426de8221f..3de254c9af 100644
--- a/packages/docs/components/transitions/previews.tsx
+++ b/packages/docs/components/transitions/previews.tsx
@@ -21,7 +21,7 @@ import type {SlideDirection} from '@remotion/transitions/slide';
import {slide} from '@remotion/transitions/slide';
import type {WipeDirection} from '@remotion/transitions/wipe';
import {wipe} from '@remotion/transitions/wipe';
-import React, {useCallback, useEffect, useRef} from 'react';
+import React, {useEffect, useRef} from 'react';
import type {SpringConfig} from 'remotion';
import {AbsoluteFill, measureSpring, spring, useVideoConfig} from 'remotion';
import {
@@ -253,53 +253,47 @@ export const PresentationPreview: React.FC<{
readonly durationRestThreshold: number;
}> = ({effect, durationRestThreshold}) => {
const ref = useRef<PlayerRef>(null);
- const wrapperRef = useRef<HTMLDivElement>(null);
- const playFromStart = useCallback(() => {
- ref.current?.seekTo(0);
- ref.current?.play();
- }, []);
-
- // `pointerenter` only fires when the pointer transitions into the
- // element, so if the cursor happens to already be inside the tile when
- // the component mounts (very common on this page because the tiles are
- // small and tightly packed), the first hover after page load is missed
- // and the preview never plays. Trigger the preview once on mount in
- // that case so the behavior is reliable.
useEffect(() => {
- if (wrapperRef.current?.matches(':hover')) {
- playFromStart();
+ const {current} = ref;
+ if (!current) {
+ return;
}
- }, [playFromStart]);
+
+ const callback = () => {
+ current?.seekTo(0);
+ current?.play();
+ };
+
+ current?.getContainerNode()?.addEventListener('pointerenter', callback);
+
+ return () => {
+ current
+ ?.getContainerNode()
+ ?.removeEventListener('pointerenter', callback);
+ };
+ }, []);
return (
- <div
- ref={wrapperRef}
- onPointerEnter={playFromStart}
+ <Player
+ ref={ref}
+ acknowledgeRemotionLicense
+ component={SampleTransition}
+ compositionHeight={presentationCompositionHeight}
+ compositionWidth={presentationCompositionWidth}
+ durationInFrames={60}
+ fps={30}
+ initiallyMuted
+ numberOfSharedAudioTags={0}
style={{
- display: 'flex',
+ height: 60,
borderRadius: 6,
- overflow: 'hidden',
}}
- >
- <Player
- ref={ref}
- acknowledgeRemotionLicense
- component={SampleTransition}
- compositionHeight={presentationCompositionHeight}
- compositionWidth={presentationCompositionWidth}
- durationInFrames={60}
- fps={30}
- numberOfSharedAudioTags={0}
- style={{
- height: 60,
- }}
- inputProps={{
- effect,
- durationRestThreshold,
- small: true,
- }}
- />
- </div>
+ inputProps={{
+ effect,
+ durationRestThreshold,
+ small: true,
+ }}
+ />
);
};