Skip to content

@remotion/media: Prevent MediaPlayer reinit on Sequence durationInFrames change#6914

Merged
JonnyBurger merged 1 commit intomainfrom
fix/media-player-duration-reinit
Mar 26, 2026
Merged

@remotion/media: Prevent MediaPlayer reinit on Sequence durationInFrames change#6914
JonnyBurger merged 1 commit intomainfrom
fix/media-player-duration-reinit

Conversation

@JonnyBurger
Copy link
Copy Markdown
Member

Summary

  • When a parent <Sequence>'s durationInFrames changes, videoConfig.durationInFrames (derived from SequenceContext) was in the useEffect dependency array that creates the MediaPlayer instance, causing a full dispose + recreate and a visible blink in preview
  • useCommonEffects already handles durationInFrames updates via mediaPlayer.setDurationInFrames() in a useLayoutEffect, so full reinit is unnecessary
  • Use a ref (initialDurationInFrames) for the constructor's initial value (consistent with trimAfter, trimBefore, playbackRate, etc.) and remove videoConfig.durationInFrames from the useEffect dep array
  • Applied to both VideoForPreviewAssertedShowing and AudioForPreviewAssertedShowing

Test plan

  • Verify in preview: change parent <Sequence> durationInFrames<Video> should update smoothly without blinking
  • Verify audio continues playing without interruption when parent sequence duration changes
  • Verify initial render still works correctly (ref captures correct initial value)
  • Verify setDurationInFrames() in useCommonEffects keeps MediaPlayer in sync after duration changes

🤖 Generated with Claude Code

… changes

When a parent <Sequence>'s durationInFrames changes, videoConfig.durationInFrames
updates via SequenceContext, which was triggering full MediaPlayer dispose+recreate
causing a visible blink in preview. Since useCommonEffects already handles
durationInFrames updates via mediaPlayer.setDurationInFrames(), the constructor
only needs the initial value. Use a ref for the initial value (consistent with
trimAfter, trimBefore, playbackRate, etc.) and remove from the useEffect dep array.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pullfrog
Copy link
Copy Markdown
Contributor

pullfrog bot commented Mar 26, 2026

Reviewed PR #6914 — approved. The fix correctly aligns durationInFrames with the existing ref pattern used by all other constructor-only values, eliminating unnecessary MediaPlayer reinit when parent <Sequence> duration changes.

Task list (5/5 completed)
  • Read the PR diff
  • Read surrounding source context for both changed files
  • Verify useCommonEffects handles durationInFrames updates
  • Check for consistency with trimAfter/trimBefore/playbackRate ref pattern
  • Submit review or report progress
Pullfrog  | [View workflow run](https://github.com/remotion-dev/remotion/actions/runs/23592371885/job/68700506057) | Triggered by [Pullfrog](https://pullfrog.com) | Using `Big Pickle` (free) | [𝕏](https://x.com/pullfrogai)

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
bugs Ready Ready Preview, Comment Mar 26, 2026 11:42am
remotion Ready Ready Preview, Comment Mar 26, 2026 11:42am

Request Review

@JonnyBurger JonnyBurger changed the title fix: prevent MediaPlayer reinit on Sequence durationInFrames change @remotion/media: Prevent MediaPlayer reinit on Sequence durationInFrames change Mar 26, 2026
Copy link
Copy Markdown
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct fix. useCommonEffects already handles runtime durationInFrames updates via setDurationInFrames() in a useLayoutEffect, so the full MediaPlayer reinit was unnecessary. The ref pattern is consistent with how trimBefore, trimAfter, playbackRate, and the other constructor-only values are already handled.

Pullfrog  | View workflow run | Using Big Pickle (free) | 𝕏

@JonnyBurger JonnyBurger merged commit 518bcc1 into main Mar 26, 2026
19 checks passed
@JonnyBurger JonnyBurger deleted the fix/media-player-duration-reinit branch March 26, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant