🎥 Make videos programmatically with React
preloadAudio() API
Jonny Burgerb8433c8037b5
diff --git a/packages/docs/docs/player/preloading.md b/packages/docs/docs/player/preloading.mdindex e906a2dd4d..44cc4c1ff9 100644--- a/packages/docs/docs/player/preloading.md+++ b/packages/docs/docs/player/preloading.md@@ -17,3 +17,18 @@ const unpreload = preloadVideo("https://example.com/video.mp4");// Later, you can optionally clean up the preloadunpreload();```++## Preloading videos using `@remotion/preload`++For audio, you can use the [`preloadAudio()`](/docs/preload/preload-audio) API. Put this outside a component (or inside an `useEffect`):++```tsx twoslash+import { preloadAudio } from "@remotion/preload";++const unpreload = preloadAudio(+ "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"+);++// Later, you can optionally clean up the preload+unpreload();+```diff --git a/packages/docs/docs/preload/preload-audio.md b/packages/docs/docs/preload/preload-audio.mdnew file mode 100644index 0000000000..5f6fc156df--- /dev/null+++ b/packages/docs/docs/preload/preload-audio.md@@ -0,0 +1,33 @@+---+id: preload-audio+slug: preload-audio+title: "preloadAudio()"+---++_This function is part of the [`@remotion/preload`](/docs/preload) package._++This function preloads audio in the DOM so that when a audio tag is mounted, it can play immediately.++While preload is not necessary for rendering, it can help with seamless playback in the [`<Player />`](/docs/player) and in the preview.++## Usage++```tsx twoslash+import { preloadAudio } from "@remotion/preload";++const unpreload = preloadAudio(+ "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"+);++// If you want to un-preload the audio later+unpreload();+```++## How it works++- On Firefox, it appends a `<link rel="preload" as="audio">` tag in the head element of the document.+- In other browsers, it appends a `<audio preload="auto">` tag in the body element of the document.++## See also++- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/preload/src/preload-audio.ts)diff --git a/packages/docs/docs/preload/preload-video.md b/packages/docs/docs/preload/preload-video.mdindex f4521780de..c2c935d892 100644--- a/packages/docs/docs/preload/preload-video.md+++ b/packages/docs/docs/preload/preload-video.md@@ -31,4 +31,4 @@ unpreload();## See also-- [Source code for this function](`https://github.com/remotion-dev/remotion/blob/main/packages/preload/src/preload-video.ts`)+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/preload/src/preload-video.ts)diff --git a/packages/docs/docs/preload/preload.md b/packages/docs/docs/preload/preload.mdindex 3fefd8e771..b4c1fe21bd 100644--- a/packages/docs/docs/preload/preload.md+++ b/packages/docs/docs/preload/preload.md@@ -7,9 +7,10 @@ title: "@remotion/preload"import Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';-This package provides functions for preloading assets. While preload is not necessary for rendering, it can help with seamless playback in the [`<Player />`](/docs/player) and in the preview. Currently, only one function is implemented:+This package provides functions for preloading assets. While preload is not necessary for rendering, it can help with seamless playback in the [`<Player />`](/docs/player) and in the preview. Currently, two functions are implemented:- [`preloadVideo()`](/docs/preload/preload-video)+- [`preloadAudio()`](/docs/preload/preload-audio)## Installationdiff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 0565099740..bbdf0878da 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -226,7 +226,7 @@ module.exports = {type: "doc",id: "preload/preload",},- items: ["preload/preload-video"],+ items: ["preload/preload-video", "preload/preload-audio"],},{type: "link",