Skip to content

🎥 Make videos programmatically with React

remotion: Add documentation for useMediaInTimeline hook

copilot-swe-agent[bot]2de3933a89d6
diff --git a/packages/docs/docs/use-media-in-timeline.mdx b/packages/docs/docs/use-media-in-timeline.mdx
new file mode 100644
index 0000000000..4a828745a6
--- /dev/null
+++ b/packages/docs/docs/use-media-in-timeline.mdx
@@ -0,0 +1,89 @@
+---
+image: /generated/articles-docs-use-media-in-timeline.png
+title: useMediaInTimeline()
+id: use-media-in-timeline
+crumb: 'API'
+---
+
+_available from v4.0.356_
+
+This hook allows you to register media in the Remotion Studio timeline without needing a direct reference to the media element.
+
+This is particularly useful when creating custom media components that need to appear in the timeline but don't directly manage the HTML media element.
+
+## Example
+
+```tsx twoslash
+import React from 'react';
+import {useMediaInTimeline} from 'remotion';
+
+export const MyCustomAudio: React.FC<{src: string}> = ({src}) => {
+ useMediaInTimeline({
+ volume: 1,
+ mediaVolume: 1,
+ src,
+ mediaType: 'audio',
+ playbackRate: 1,
+ displayName: 'My Custom Audio',
+ id: 'my-custom-audio',
+ stack: null,
+ showInTimeline: true,
+ premountDisplay: null,
+ postmountDisplay: null,
+ });
+
+ return null;
+};
+```
+
+## API
+
+### `volume`
+
+The volume of the media, either as a number between 0 and 1, or as a function that returns a number based on the frame.
+
+### `mediaVolume`
+
+The intrinsic volume of the media element (typically 1).
+
+### `src`
+
+The source URL of the media file.
+
+### `mediaType`
+
+Either `"audio"` or `"video"`.
+
+### `playbackRate`
+
+The playback rate of the media (default: 1).
+
+### `displayName`
+
+The name to display in the timeline. If `null`, the filename will be used.
+
+### `id`
+
+A unique identifier for this media instance.
+
+### `stack`
+
+Optional stack trace for debugging purposes.
+
+### `showInTimeline`
+
+Whether to show this media in the Remotion Studio timeline.
+
+### `premountDisplay`
+
+Internal prop for premounting (typically `null`).
+
+### `postmountDisplay`
+
+Internal prop for postmounting (typically `null`).
+
+## See also
+
+- [`<Audio />`](/docs/media/audio)
+- [`<Video />`](/docs/video)
+- [`useVideoConfig()`](/docs/use-video-config)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 48eb6b7fc7..2e04b09f35 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -171,6 +171,7 @@ const sidebars: SidebarsConfig = {
'use-current-frame',
'use-current-scale',
'use-delay-render',
+ 'use-media-in-timeline',
'use-remotion-environment',
'use-video-config',
'version',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index e1ac95194a..2e98608522 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -6115,6 +6115,15 @@ export const articles = [
noAi: false,
slug: 'use-img-and-iframe',
},
+ {
+ id: 'use-media-in-timeline',
+ title: 'useMediaInTimeline()',
+ relativePath: 'docs/use-media-in-timeline.mdx',
+ compId: 'articles-docs-use-media-in-timeline',
+ crumb: 'API',
+ noAi: false,
+ slug: 'use-media-in-timeline',
+ },
{
id: 'use-offthread-video-texture',
title: 'useOffthreadVideoTexture()',
diff --git a/packages/docs/static/generated/articles-docs-use-media-in-timeline.png b/packages/docs/static/generated/articles-docs-use-media-in-timeline.png
new file mode 100644
index 0000000000..d6b8a20371
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-use-media-in-timeline.png differ