🎥 Make videos programmatically with React
`@remotion/player`: Change `numberOfSharedAudioTags` default to 0 in v5 (#11445)
Igor Samokhovets250f0606a365
diff --git a/packages/docs/docs/5-0-migration.mdx b/packages/docs/docs/5-0-migration.mdxindex 2027848add..23787e85d8 100644--- a/packages/docs/docs/5-0-migration.mdx+++ b/packages/docs/docs/5-0-migration.mdx@@ -181,6 +181,12 @@ This prevents black frames that were commonly seen when a `<Sequence>` containin**Required action**: If you don't want this behavior for a specific Sequence, opt out by passing [`premountFor={0}`](/docs/sequence#premountfor).+## `<Player>` does not create shared audio tags by default++The default [`numberOfSharedAudioTags`](/docs/player/player#numberofsharedaudiotags) value of the [`<Player>`](/docs/player/player) has changed from `5` to `0`.++**Required action**: If you rely on shared audio tags to work around browser autoplay policies, set `numberOfSharedAudioTags={5}` or another value that covers the maximum number of [`<Html5Audio>`](/docs/html5-audio) tags playing at the same time.+## Media and images pause playback while loading[`<Video>`](/docs/media/video) and [`<Audio>`](/docs/media/audio) from [`@remotion/media`](/docs/media) have paused playback while loading by default since they were introduced.diff --git a/packages/docs/docs/player/api.mdx b/packages/docs/docs/player/api.mdxindex 52ec70bbde..b8fd04fd53 100644--- a/packages/docs/docs/player/api.mdx+++ b/packages/docs/docs/player/api.mdx@@ -118,9 +118,9 @@ Start the playback from a specific frame. Default `0`. Once the player is mounteIf you use an [`<Html5Audio />`](/docs/html5-audio) tag, it might not play in some browsers (specifically iOS Safari) due to browser autoplay policies. This is why the Remotion Player pre-mounts a set of audio tags with silent audio that get played upon user interaction. These audio tags can then be used to play real audio later and will not be subject to the autoplay policy of the browser.-This option controls how many audio tags are being rendered, the default is `5`. If you mount more audio tags than shared audio tags are available, then an error will be thrown.+This option controls how many shared audio tags are rendered. In Remotion 4.0, the default is `5`. In Remotion 5.0, the default is `0`. If you mount more audio tags than shared audio tags are available, an error will be thrown.-If you'd like to opt out of this behavior, you can pass `0` to mount native audio tags simultaneously as you mount Remotion's [`<Html5Audio />`](/docs/html5-audio) tags.+Pass a value greater than `0` to enable this behavior. With `0`, each [`<Html5Audio />`](/docs/html5-audio) mounts its own native `<audio>` element when it appears.Once you have set this prop, you cannot change it anymore or an error will be thrown.diff --git a/packages/docs/docs/player/autoplay.mdx b/packages/docs/docs/player/autoplay.mdxindex 4b66862039..be7a4d9c58 100644--- a/packages/docs/docs/player/autoplay.mdx+++ b/packages/docs/docs/player/autoplay.mdx@@ -90,10 +90,12 @@ There are three different cases here:## Using the `numberOfSharedAudioTags` prop-By default, Remotion will mount 5 auxiliary `<audio>` tags that will "warm" up with the first user interaction.+In Remotion 4.0, Remotion mounts 5 auxiliary `<audio>` tags by default that will "warm" up with the first user interaction.If an `<Html5Audio>` tag is played after the first user interaction, it will be mounted into one of the auxiliary tags and will be allowed to play.-If you have more than 5 `<Html5Audio>` tags that play at the same time, you can increase the number of auxiliary tags by passing the [`numberOfSharedAudioTags`](/docs/player/player#numberofsharedaudiotags) prop to the `<Player>`, because otherwise an error will be thrown.+If you use Remotion 4.0 and have more than 5 `<Html5Audio>` tags that play at the same time, you can increase the number of auxiliary tags by passing the [`numberOfSharedAudioTags`](/docs/player/player#numberofsharedaudiotags) prop to the `<Player>`, because otherwise an error will be thrown.++In Remotion 5.0, `numberOfSharedAudioTags` defaults to `0`. Pass a positive value to enable shared audio tags.## Dealing with an autoplay failure<AvailableFrom v="4.0.187" />diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsxindex d363a7fcea..4c70214194 100644--- a/packages/player/src/Player.tsx+++ b/packages/player/src/Player.tsx@@ -19,6 +19,7 @@ import type {TimelineContextValue,} from 'remotion';import {Composition, Internals} from 'remotion';+import {NoReactInternals} from 'remotion/no-react';import type {BrowserMediaControlsBehavior} from './browser-mediasession.js';import {PlayerEmitterProvider} from './EmitterProvider.js';import type {RenderMuteButton} from './MediaVolumeSlider.js';@@ -152,7 +153,9 @@ const PlayerFn = <doubleClickToFullscreen = false,spaceKeyToPlayOrPause = true,moveToBeginningWhenEnded = true,- numberOfSharedAudioTags = 5,+ numberOfSharedAudioTags = NoReactInternals.ENABLE_V5_BREAKING_CHANGES+ ? 0+ : 5,errorFallback = () => '⚠️',playbackRate = 1,renderLoading,diff --git a/packages/player/src/test/index.test.ts b/packages/player/src/test/index.test.tsindex 61695f362e..eee795395c 100644--- a/packages/player/src/test/index.test.ts+++ b/packages/player/src/test/index.test.ts@@ -1,6 +1,7 @@import {afterEach, expect, test} from 'bun:test';import React, {createRef, useRef} from 'react';import {Html5Audio, Internals, useCurrentFrame} from 'remotion';+import {NoReactInternals} from 'remotion/no-react';import type {PlayerRef} from '../player-methods.js';import {Player} from '../Player.js';import {Thumbnail} from '../Thumbnail.js';@@ -38,6 +39,22 @@ test('Thumbnail supports usePlaying in its composition', () => {expect(view.getByText('paused')).toBeTruthy();});+test('Player uses the version-specific default number of shared audio tags', () => {+ const view = render(+ React.createElement(Player, {+ component: () => null,+ durationInFrames: 100,+ compositionWidth: 1920,+ compositionHeight: 1080,+ fps: 30,+ }),+ );++ expect(view.container.querySelectorAll('audio')).toHaveLength(+ NoReactInternals.ENABLE_V5_BREAKING_CHANGES ? 0 : 5,+ );+});+test('Seeking to the current frame does not rerender the composition', () => {let compositionRenders = 0;const playerRef = createRef<PlayerRef>();