packages/docs/docs/player/media-keys.mdx
This document is about the behavior when a user:
These behaviors are controlled by the browserMediaControlsBehavior prop.
The underlying Web API used is the Media Session API.
prevent-media-session (default)const otherProps = {
compositionHeight: 720,
compositionWidth: 1280,
inputProps: {},
durationInFrames: 120,
fps: 30,
component: () => null,
};
// ---cut---
import {Player} from '@remotion/player';
export const MyComp: React.FC = () => {
return (
<Player
browserMediaControlsBehavior={{
mode: 'prevent-media-session',
}}
{...otherProps}
/>
);
};
In this mode, Remotion will not act on the user's media keys, but map any keybord action to a no-op.
This prevents that the Player is paused but the audio tags get resumed by pressing the Play/Pause button on the keyboard, which was a problem prior to Remotion v4.0.221.
register-media-sessionconst otherProps = {
compositionHeight: 720,
compositionWidth: 1280,
inputProps: {},
durationInFrames: 120,
fps: 30,
component: () => null,
};
// ---cut---
import {Player} from '@remotion/player';
export const MyComp: React.FC = () => {
return (
<Player
browserMediaControlsBehavior={{
mode: 'register-media-session',
}}
{...otherProps}
/>
);
};
In this mode, Remotion will use the Media Session API to register handlers:
Also, Remotion will react to seeking events and inform the device about the current playback position and duration.
do-nothingconst otherProps = {
compositionHeight: 720,
compositionWidth: 1280,
inputProps: {},
durationInFrames: 120,
fps: 30,
component: () => null,
};
// ---cut---
import {Player} from '@remotion/player';
export const MyComp: React.FC = () => {
return (
<Player
browserMediaControlsBehavior={{
mode: 'do-nothing',
}}
{...otherProps}
/>
);
};
Reverts to the behavior prior to Remotion v4.0.221.
Remotion will not react to any media keys, leaving the browser to handle the media keys.
This leads to the problem that the user can resume any media tag by pressing the Play/Pause button on the keyboard, without the Remotion Player also resuming.
<Player>'sRemotion's register-media-session handler is supposed to only work with 1 Player mounted.
It is not defined which Player reacts to the media keys.
When working with multiple Players, set one to do-nothing mode and the other to register-media-session mode to explicitly set the Media Keys for only 1 Player.
If you want all Players to react to the media keys, you need to use do-nothing mode and implement this behavior yourself with the Player API.
The behavior is set to register-media-session as of v4.0.221 and previously it behaved like do-nothing.