Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
fix: player autoplay
dev_wandrya69773c5a527
diff --git a/app/(home)/components/sections/bento-registry.tsx b/app/(home)/components/sections/bento-registry.tsxindex 0967a468..8bf7a800 100644--- a/app/(home)/components/sections/bento-registry.tsx+++ b/app/(home)/components/sections/bento-registry.tsx@@ -1,10 +1,10 @@"use client";-import { Player } from "@remotion/player";+import { Player, type PlayerRef } from "@remotion/player";import { ArrowRight, Check, Copy } from "lucide-react";import { motion } from "motion/react";import Link from "next/link";-import { useState } from "react";+import { useEffect, useRef, useState } from "react";import { Button } from "@/components/ui/button";import { SPRING_SOFT } from "@/config/site";import { useTrackEvent } from "@/lib/analytics";@@ -78,6 +78,29 @@ function BentoCard({featured?: boolean;}) {const entry = registry[name];+ const playerRef = useRef<PlayerRef>(null);++ // Reliable autoplay — `<Player autoPlay>` mounts a tick before its imperative+ // handle is ready (worse under Strict Mode's dev double-mount) and silently+ // stalls; mount paused and drive play() via the ref on the next animation+ // frame with a one-shot retry. Mirrors PreviewStage / use-player-controls.ts.+ useEffect(() => {+ if (!entry) return;+ let raf1 = 0;+ let raf2 = 0;+ raf1 = requestAnimationFrame(() => {+ playerRef.current?.play();+ raf2 = requestAnimationFrame(() => {+ if (playerRef.current && !playerRef.current.isPlaying()) {+ playerRef.current.play();+ }+ });+ });+ return () => {+ if (raf1) cancelAnimationFrame(raf1);+ if (raf2) cancelAnimationFrame(raf2);+ };+ }, [entry]);return (<motion.div@@ -111,6 +134,7 @@ function BentoCard({>{entry ? (<Player+ ref={playerRef}component={entry.Component}inputProps={inputProps ?? {}}durationInFrames={entry.config.durationInFrames}@@ -118,7 +142,6 @@ function BentoCard({compositionWidth={entry.config.compositionWidth}compositionHeight={entry.config.compositionHeight}style={{ width: "100%", height: "100%" }}- autoPlayloopacknowledgeRemotionLicense/>diff --git a/app/(home)/components/sections/hero.tsx b/app/(home)/components/sections/hero.tsxindex 65a28749..f99cd64f 100644--- a/app/(home)/components/sections/hero.tsx+++ b/app/(home)/components/sections/hero.tsx@@ -4,7 +4,7 @@ import { Player, type PlayerRef } from "@remotion/player";import { ArrowRight, Pause, Play } from "lucide-react";import { motion } from "motion/react";import Link from "next/link";-import { useCallback, useRef, useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";import { Badge } from "@/components/ui/badge";import { Button } from "@/components/ui/button";import { INSTALL_COMMAND, SPRING_BOUNCE } from "@/config/site";@@ -41,6 +41,28 @@ export function Hero() {}}, [trackEvent]);+ // Reliable autoplay — `<Player autoPlay>` mounts a tick before its imperative+ // handle is ready (worse under Strict Mode's dev double-mount) and silently+ // stalls (Pause UI, frozen frame). Mount paused and drive play() via the ref+ // on the next animation frame with a one-shot retry. Mirrors PreviewStage /+ // stars/hooks/use-player-controls.ts.+ useEffect(() => {+ let raf1 = 0;+ let raf2 = 0;+ raf1 = requestAnimationFrame(() => {+ playerRef.current?.play();+ raf2 = requestAnimationFrame(() => {+ if (playerRef.current && !playerRef.current.isPlaying()) {+ playerRef.current.play();+ }+ });+ });+ return () => {+ if (raf1) cancelAnimationFrame(raf1);+ if (raf2) cancelAnimationFrame(raf2);+ };+ }, []);+const aspectRatio = heroEntry? `${heroEntry.config.compositionWidth} / ${heroEntry.config.compositionHeight}`: "16 / 9";@@ -151,7 +173,6 @@ export function Hero() {compositionWidth={heroEntry.config.compositionWidth}compositionHeight={heroEntry.config.compositionHeight}style={{ width: "100%", height: "100%", display: "block" }}- autoPlayloopacknowledgeRemotionLicense/>diff --git a/app/(home)/components/sections/interactive-code.tsx b/app/(home)/components/sections/interactive-code.tsxindex d255dcfa..0106b623 100644--- a/app/(home)/components/sections/interactive-code.tsx+++ b/app/(home)/components/sections/interactive-code.tsx@@ -1,11 +1,12 @@"use client";-import { Player } from "@remotion/player";+import { Player, type PlayerRef } from "@remotion/player";import { motion } from "motion/react";import {type KeyboardEvent,type PointerEvent,useCallback,+ useEffect,useMemo,useRef,useState,@@ -253,6 +254,29 @@ function ToggleBool({export function InteractiveCode() {const entry = registry[COMPONENT];+ const playerRef = useRef<PlayerRef>(null);++ // Reliable autoplay — `<Player autoPlay>` mounts a tick before its imperative+ // handle is ready (worse under Strict Mode's dev double-mount) and silently+ // stalls; mount paused and drive play() via the ref on the next animation+ // frame with a one-shot retry. Mirrors PreviewStage / use-player-controls.ts.+ useEffect(() => {+ if (!entry) return;+ let raf1 = 0;+ let raf2 = 0;+ raf1 = requestAnimationFrame(() => {+ playerRef.current?.play();+ raf2 = requestAnimationFrame(() => {+ if (playerRef.current && !playerRef.current.isPlaying()) {+ playerRef.current.play();+ }+ });+ });+ return () => {+ if (raf1) cancelAnimationFrame(raf1);+ if (raf2) cancelAnimationFrame(raf2);+ };+ }, [entry]);const [text, setText] = useState(TYPEWRITER_DEFAULTS.text);const [fontSize, setFontSize] = useState(TYPEWRITER_DEFAULTS.fontSize);@@ -357,6 +381,7 @@ export function InteractiveCode() {<div className="w-full" style={{ aspectRatio }}>{entry ? (<Player+ ref={playerRef}component={entry.Component}inputProps={inputProps}durationInFrames={entry.config.durationInFrames}@@ -364,7 +389,6 @@ export function InteractiveCode() {compositionWidth={entry.config.compositionWidth}compositionHeight={entry.config.compositionHeight}style={{ width: "100%", height: "100%", display: "block" }}- autoPlayloopacknowledgeRemotionLicense/>diff --git a/components/docs/component-card.tsx b/components/docs/component-card.tsxindex fcf3365d..49db524d 100644--- a/components/docs/component-card.tsx+++ b/components/docs/component-card.tsx@@ -1,6 +1,6 @@"use client";-import { Player, Thumbnail } from "@remotion/player";+import { Player, type PlayerRef, Thumbnail } from "@remotion/player";import Link from "next/link";import { type ReactNode, useEffect, useRef, useState } from "react";import { getDefaults } from "@/lib/customizer-config";@@ -31,6 +31,7 @@ function PreviewPlaceholder() {function CardPreview({ item }: { item: CardItem }) {const reducedMotion = usePrefersReducedMotion();const ref = useRef<HTMLDivElement>(null);+ const playerRef = useRef<PlayerRef>(null);const [inView, setInView] = useState(false);useEffect(() => {@@ -52,6 +53,29 @@ function CardPreview({ item }: { item: CardItem }) {const slug = slugFromHref(item.href);const entry = slug ? registry[slug] : undefined;+ const showPlayer =+ item.status === "stable" && !!entry && inView && !reducedMotion;++ // Same reliable-autoplay shim as PreviewStage: `<Player autoPlay>` mounts a+ // tick before its imperative handle is ready and silently fails to start, so+ // we drive play() via the ref once the player is shown, retrying once.+ useEffect(() => {+ if (!showPlayer) return;+ let raf1 = 0;+ let raf2 = 0;+ raf1 = requestAnimationFrame(() => {+ playerRef.current?.play();+ raf2 = requestAnimationFrame(() => {+ if (playerRef.current && !playerRef.current.isPlaying()) {+ playerRef.current.play();+ }+ });+ });+ return () => {+ if (raf1) cancelAnimationFrame(raf1);+ if (raf2) cancelAnimationFrame(raf2);+ };+ }, [showPlayer]);let content: ReactNode;if (item.status !== "stable" || !entry || !inView) {@@ -62,6 +86,7 @@ function CardPreview({ item }: { item: CardItem }) {const playing = !reducedMotion;content = playing ? (<Player+ ref={playerRef}component={Component}inputProps={inputProps}durationInFrames={config.durationInFrames}@@ -71,7 +96,6 @@ function CardPreview({ item }: { item: CardItem }) {style={{ width: "100%", height: "100%" }}controls={false}loop- autoPlayacknowledgeRemotionLicense/>) : (diff --git a/lib/ui-preview-internals.tsx b/lib/ui-preview-internals.tsxindex d66d7110..73fef74d 100644--- a/lib/ui-preview-internals.tsx+++ b/lib/ui-preview-internals.tsx@@ -1,6 +1,6 @@"use client";-import { Player } from "@remotion/player";+import { Player, type PlayerRef } from "@remotion/player";import { PlayIcon } from "lucide-react";import {parseAsBoolean,@@ -81,6 +81,7 @@ export function PreviewStage({}) {const [mounted, setMounted] = useState(false);const frameRef = useRef<HTMLDivElement>(null);+ const playerRef = useRef<PlayerRef>(null);const reducedMotion = usePrefersReducedMotion();useEffect(() => {@@ -100,6 +101,30 @@ export function PreviewStage({return () => observer.disconnect();}, [mounted]);+ // Reliable autoplay. The `<Player autoPlay>` prop mounts a tick before its+ // imperative handle is ready (worse under Strict Mode's dev double-mount), so+ // it shows the "playing" UI but the frame loop never starts — the preview+ // looks frozen until a manual pause/play. Instead the Player mounts paused and+ // we drive play() via the ref on the next animation frame, retrying once if+ // the first call didn't take. Mirrors stars/hooks/use-player-controls.ts.+ useEffect(() => {+ if (!mounted) return;+ let raf1 = 0;+ let raf2 = 0;+ raf1 = requestAnimationFrame(() => {+ playerRef.current?.play();+ raf2 = requestAnimationFrame(() => {+ if (playerRef.current && !playerRef.current.isPlaying()) {+ playerRef.current.play();+ }+ });+ });+ return () => {+ if (raf1) cancelAnimationFrame(raf1);+ if (raf2) cancelAnimationFrame(raf2);+ };+ }, [mounted]);+return (<divref={frameRef}@@ -118,6 +143,7 @@ export function PreviewStage({)}><Player+ ref={playerRef}component={Component}inputProps={inputProps}durationInFrames={durationInFrames}@@ -127,7 +153,6 @@ export function PreviewStage({style={{ width: "100%", height: "100%" }}controlsloop- autoPlayacknowledgeRemotionLicense/></div>