🎥 Make videos programmatically with React
offthreadvideo while rendering
Jonny Burger59888c09802d
diff --git a/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.md b/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.mdnew file mode 100644index 0000000000..b0982a10dd--- /dev/null+++ b/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.md@@ -0,0 +1,30 @@+---+title: "<OffthreadVideo /> while rendering"+---++The following component will only use [`<OffthreadVideo />`](/docs/offthreadvideo) while rendering, but [`<Video />`](/docs/video) in the Player.+This is useful for attaching a `ref` to the [`<Video />`](/docs/video) tag.++`window.remotion_isPlayer` is used to determine if the environment is a Player, but this is not an official Remotion API that is guaranteed to be reliable. It's better if you define your own global variable `window.myApp_isPlayer = true` in your Webapp to declare that this is a Player environment.++```tsx twoslash+import { forwardRef } from "react";+import { OffthreadVideo, RemotionOffthreadVideoProps, Video } from "remotion";++const OffthreadWhileRenderingRefForwardingFunction: React.ForwardRefRenderFunction<+ HTMLVideoElement,+ RemotionOffthreadVideoProps+> = (props, ref) => {+ const { imageFormat, ...otherProps } = props;++ if (window.remotion_isPlayer) {+ return <Video ref={ref} {...otherProps}></Video>;+ }++ return <OffthreadVideo {...props}></OffthreadVideo>;+};++export const OffthreadVideoWhileRendering = forwardRef(+ OffthreadWhileRenderingRefForwardingFunction+);+```diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex b8eb65a957..9ad3436fd0 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -332,6 +332,7 @@ module.exports = {"miscellaneous/snippets/player-in-iframe","miscellaneous/snippets/fps-converter","miscellaneous/snippets/adding-animations",+ "miscellaneous/snippets/offthread-video-while-rendering",],},],