Skip to content

🎥 Make videos programmatically with React

fullscreen imperative methods

Jonny Burger6d2d8ced2769
diff --git a/packages/docs/docs/player.md b/packages/docs/docs/player.md
index 41d08e5aa3..25f193078d 100644
--- a/packages/docs/docs/player.md
+++ b/packages/docs/docs/player.md
@@ -1,6 +1,6 @@
---
id: player
-title: <Player />
+title: API - @remotion/player
---
import Tabs from '@theme/Tabs';
@@ -145,6 +145,20 @@ Gets the current postition expressed as the current frame. Divide by the `fps` y
Move the position in the video to the frame that you specify. If the video is playing, it will pause for a brief moment, then start playing again after the seek is completed.
+### `isFullscreen()`
+
+Returns a boolean whether the video is currently playing in fullscreen.
+
+_To observe the fullscreen state and react to changes, listen to the [`fullscreenchange`](https://developer.mozilla.org/en-US/docs/Web/API/Document/fullscreenchange_event) event on the global document._
+
+### `requestFullscreen()`
+
+Requests the video to go to fullscreen. This method throws if the `allowFullscreen` prop is false or the browser doesn't support allow the player to go into fullscreen.
+
+### `exitFullscreen()`
+
+Exit fullscreen mode.
+
### `addEventListener()`
Start listening to an event. See the [Events](#events) section to see the function signature and the available events.
diff --git a/packages/player/src/PlayerControls.tsx b/packages/player/src/PlayerControls.tsx
index d1a75c91de..8edd14fa89 100644
--- a/packages/player/src/PlayerControls.tsx
+++ b/packages/player/src/PlayerControls.tsx
@@ -115,7 +115,7 @@ export const Controls: React.FC<{
{formatTime(frame / fps)} / {formatTime(durationInFrames / fps)}
</div>
</div>
- {allowFullscreen ? (
+ {document.fullscreenEnabled && allowFullscreen ? (
<div style={fullscreen}>
<button
type="button"
diff --git a/packages/player/src/PlayerUI.tsx b/packages/player/src/PlayerUI.tsx
index 8f0e9d5f4a..af3f96d384 100644
--- a/packages/player/src/PlayerUI.tsx
+++ b/packages/player/src/PlayerUI.tsx
@@ -88,6 +88,9 @@ const PlayerUI: React.ForwardRefRenderFunction<
player.seek(f);
},
+ isFullscreen: () => isFullscreen,
+ requestFullscreen: () => requestFullScreenAccess(),
+ exitFullscreen: () => document.exitFullscreen(),
};
return Object.assign(player.emitter, methods);
});
diff --git a/packages/player/src/player-methods.ts b/packages/player/src/player-methods.ts
index 2f87cd986c..0ee1dbb6de 100644
--- a/packages/player/src/player-methods.ts
+++ b/packages/player/src/player-methods.ts
@@ -6,6 +6,9 @@ export type PlayerMethods = {
toggle: () => void;
seekTo: (frame: number) => void;
getCurrentFrame: () => number;
+ requestFullscreen: () => void;
+ exitFullscreen: () => void;
+ isFullscreen: () => void;
};
export type PlayerRef = PlayerEventTarget & PlayerMethods;