Skip to content

🎥 Make videos programmatically with React

new `initiallyMuted` prop

Jonny Burgerd7198695efa9
diff --git a/packages/docs/docs/player/api.md b/packages/docs/docs/player/api.md
index 874a4f5dd3..6753715441 100644
--- a/packages/docs/docs/player/api.md
+++ b/packages/docs/docs/player/api.md
@@ -295,6 +295,12 @@ _optional_
If true, the controls flash when the player enters the scene. After 2 seconds without hover, the controls fade out. This is similar to how YouTube does it, and signals to the user that the player is in fact controllable. You can also pass a `number`, with which you can customize the duration in milliseconds. Default `true` since `v3.2.24`, before that unsupported.
+### `initiallyMuted` <AvailableFrom v="3.3.81" />
+
+_optional_
+
+If true, the player is muted in its initial state. This is useful if the video must autoplay regardless of the [autoplay](/docs/player/autoplay) policy of the browser.
+
### `renderPlayPauseButton` <AvailableFrom v="3.2.32" />
_optional_
@@ -443,7 +449,7 @@ If you play the video from a user gesture, pass the `SyntheticEvent` in as an ar
### `getCurrentFrame()`
Gets the current position expressed as the current frame. Divide by the `fps` you passed to get the time in seconds.
-
+
[Special considerations must be made](https://www.remotion.dev/docs/player/current-time) if you want to display a component that synchronizes with the time of the player.
### `isPlaying()` <AvailableFrom v="2.5.7" />
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index 2990992856..6127169024 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -64,6 +64,7 @@ export type PlayerProps<T> = {
renderPlayPauseButton?: RenderPlayPauseButton;
renderFullscreenButton?: RenderFullscreenButton;
alwaysShowControls?: boolean;
+ initiallyMuted?: boolean;
} & PropsIfHasProps<T> &
CompProps<T>;
@@ -110,6 +111,7 @@ const PlayerFn = <T,>(
renderFullscreenButton,
renderPlayPauseButton,
alwaysShowControls = false,
+ initiallyMuted = false,
...componentProps
}: PlayerProps<T>,
ref: MutableRefObject<PlayerRef>
@@ -323,6 +325,7 @@ const PlayerFn = <T,>(
fps={fps}
inputProps={inputProps}
numberOfSharedAudioTags={numberOfSharedAudioTags}
+ initiallyMuted={initiallyMuted}
>
<Internals.Timeline.SetTimelineContext.Provider
value={setTimelineContextValue}
diff --git a/packages/player/src/SharedPlayerContext.tsx b/packages/player/src/SharedPlayerContext.tsx
index a6235944d6..fb41af3c6e 100644
--- a/packages/player/src/SharedPlayerContext.tsx
+++ b/packages/player/src/SharedPlayerContext.tsx
@@ -21,6 +21,7 @@ export const SharedPlayerContexts: React.FC<{
durationInFrames: number;
component: LazyExoticComponent<ComponentType<unknown>>;
numberOfSharedAudioTags: number;
+ initiallyMuted: boolean;
}> = ({
children,
timelineContext,
@@ -31,6 +32,7 @@ export const SharedPlayerContexts: React.FC<{
durationInFrames,
component,
numberOfSharedAudioTags,
+ initiallyMuted,
}) => {
const compositionManagerContext: CompositionManagerContext = useMemo(() => {
return {
@@ -78,8 +80,10 @@ export const SharedPlayerContexts: React.FC<{
inputProps,
]);
- const [mediaMuted, setMediaMuted] = useState<boolean>(false);
- const [mediaVolume, setMediaVolume] = useState<number>(getPreferredVolume());
+ const [mediaMuted, setMediaMuted] = useState<boolean>(() => initiallyMuted);
+ const [mediaVolume, setMediaVolume] = useState<number>(() =>
+ getPreferredVolume()
+ );
const mediaVolumeContextValue = useMemo((): MediaVolumeContextValue => {
return {
diff --git a/packages/player/src/Thumbnail.tsx b/packages/player/src/Thumbnail.tsx
index 88ff7a79fe..d245c599c5 100644
--- a/packages/player/src/Thumbnail.tsx
+++ b/packages/player/src/Thumbnail.tsx
@@ -93,6 +93,7 @@ export const ThumbnailFn = <T,>(
fps={fps}
inputProps={inputProps}
numberOfSharedAudioTags={0}
+ initiallyMuted
>
<ThumbnailEmitterContext.Provider value={emitter}>
<ThumbnailUI