🎥 Make videos programmatically with React
`@remotion/media`: Less recreations of MediaPlayer() upon prop changes
Jonny Burger97432eafc7c7
diff --git a/packages/media/src/audio/audio-for-preview.tsx b/packages/media/src/audio/audio-for-preview.tsxindex 941665c9bf..bb4af37fb8 100644--- a/packages/media/src/audio/audio-for-preview.tsx+++ b/packages/media/src/audio/audio-for-preview.tsx@@ -156,6 +156,10 @@ const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({}const isPlayerBuffering = Internals.useIsPlayerBuffering(bufferingContext);+ const initialIsPremounting = useRef(isPremounting);+ const initialIsPostmounting = useRef(isPostmounting);+ const initialGlobalPlaybackRate = useRef(globalPlaybackRate);+ const initialPlaybackRate = useRef(playbackRate);useEffect(() => {if (!sharedAudioContext) return;@@ -171,13 +175,13 @@ const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({trimBefore: initialTrimBeforeRef.current,fps: videoConfig.fps,canvas: null,- playbackRate,+ playbackRate: initialPlaybackRate.current,audioStreamIndex: audioStreamIndex ?? 0,debugOverlay: false,bufferState: buffer,- isPostmounting,- isPremounting,- globalPlaybackRate,+ isPostmounting: initialIsPostmounting.current,+ isPremounting: initialIsPremounting.current,+ globalPlaybackRate: initialGlobalPlaybackRate.current,onVideoFrameCallback: null,});@@ -296,14 +300,10 @@ const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({sharedAudioContext,currentTimeRef,loop,- playbackRate,videoConfig.fps,audioStreamIndex,disallowFallbackToHtml5Audio,buffer,- isPremounting,- isPostmounting,- globalPlaybackRate,]);useLayoutEffect(() => {diff --git a/packages/media/src/video/video-for-preview.tsx b/packages/media/src/video/video-for-preview.tsxindex bbb8e9f671..c12841e3bd 100644--- a/packages/media/src/video/video-for-preview.tsx+++ b/packages/media/src/video/video-for-preview.tsx@@ -166,6 +166,10 @@ const VideoForPreviewAssertedShowing: React.FC<VideoForPreviewProps> = ({}const isPlayerBuffering = Internals.useIsPlayerBuffering(buffering);+ const initialIsPremounting = useRef(isPremounting);+ const initialIsPostmounting = useRef(isPostmounting);+ const initialGlobalPlaybackRate = useRef(globalPlaybackRate);+ const initialPlaybackRate = useRef(playbackRate);useEffect(() => {if (!sharedAudioContext) return;@@ -181,13 +185,13 @@ const VideoForPreviewAssertedShowing: React.FC<VideoForPreviewProps> = ({trimAfter: initialTrimAfterRef.current,trimBefore: initialTrimBeforeRef.current,fps: videoConfig.fps,- playbackRate,+ playbackRate: initialPlaybackRate.current,audioStreamIndex,debugOverlay,bufferState: buffer,- isPremounting,- isPostmounting,- globalPlaybackRate,+ isPremounting: initialIsPremounting.current,+ isPostmounting: initialIsPostmounting.current,+ globalPlaybackRate: initialGlobalPlaybackRate.current,onVideoFrameCallback: initialOnVideoFrameRef.current ?? null,});@@ -295,19 +299,15 @@ const VideoForPreviewAssertedShowing: React.FC<VideoForPreviewProps> = ({setShouldFallbackToNativeVideo(false);};}, [- preloadedSrc,+ audioStreamIndex,+ buffer,+ debugOverlay,+ disallowFallbackToOffthreadVideo,logLevel,- sharedAudioContext,loop,+ preloadedSrc,+ sharedAudioContext,videoConfig.fps,- playbackRate,- disallowFallbackToOffthreadVideo,- audioStreamIndex,- debugOverlay,- buffer,- isPremounting,- isPostmounting,- globalPlaybackRate,]);const classNameValue = useMemo(() => {