Skip to content

Commit 2c193e8

Browse files
committed
Add "fullscreen" button
Adds "fullscreen" buttons to the videos in the cutting tab. The goal is to give users a simple way to zoom in on a video in case they need to perceive details, like for example small text on a blackboard. TODO: Fullscreen button positioning
1 parent 8cebce8 commit 2c193e8

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/main/VideoPlayers.tsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ import { ActionCreatorWithPayload, AsyncThunk } from "@reduxjs/toolkit";
3636

3737
import { useTheme } from "../themes";
3838

39-
import { backgroundBoxStyle } from "../cssStyles";
39+
import { backgroundBoxStyle, basicButtonStyle } from "../cssStyles";
4040
import { BaseReactPlayerProps } from "react-player/base";
4141
import { ErrorBox } from "@opencast/appkit";
42+
import { LuFullscreen } from "react-icons/lu";
4243

4344
const VideoPlayers: React.FC<{
4445
refs?: React.MutableRefObject<(VideoPlayerForwardRef | null)[]>,
@@ -56,6 +57,7 @@ const VideoPlayers: React.FC<{
5657
const videoCount = useAppSelector(selectVideoCount);
5758

5859
const [videoPlayers, setVideoPlayers] = useState<JSX.Element[]>([]);
60+
const [fullscreenPlayerIndex, setFullscreenPlayerIndex] = useState<number | undefined>(undefined);
5961

6062
const videoPlayerAreaStyle = css({
6163
display: "flex",
@@ -65,7 +67,9 @@ const VideoPlayers: React.FC<{
6567
borderRadius: "5px",
6668
gap: "10px",
6769

68-
maxHeight: maxHeightInPixel + "px",
70+
maxHeight: fullscreenPlayerIndex === undefined
71+
? maxHeightInPixel + "px"
72+
: maxHeightInPixel * 2 + "px",
6973
});
7074

7175
// Initialize video players
@@ -81,6 +85,8 @@ const VideoPlayers: React.FC<{
8185
subtitleUrl={""}
8286
first={i === 0}
8387
last={i === videoCount - 1}
88+
fullscreenPlayerIndex={fullscreenPlayerIndex}
89+
setFullscreenPlayerIndex={setFullscreenPlayerIndex}
8490
selectIsPlaying={selectIsPlaying}
8591
selectIsMuted={selectIsMuted}
8692
selectVolume={selectVolume}
@@ -103,7 +109,7 @@ const VideoPlayers: React.FC<{
103109
);
104110
}
105111
setVideoPlayers(videoPlayers);
106-
}, [primaryIndex, refs, videoCount, videos]);
112+
}, [primaryIndex, refs, videoCount, videos, fullscreenPlayerIndex]);
107113

108114

109115
return (
@@ -125,6 +131,8 @@ interface VideoPlayerProps {
125131
subtitleUrl: string,
126132
first: boolean,
127133
last: boolean,
134+
fullscreenPlayerIndex: number | undefined,
135+
setFullscreenPlayerIndex: (index: number | undefined) => void,
128136
selectIsPlaying: (state: RootState) => boolean,
129137
selectIsMuted: (state: RootState) => boolean,
130138
selectVolume: (state: RootState) => number,
@@ -167,6 +175,8 @@ export const VideoPlayer = React.forwardRef<VideoPlayerForwardRef, VideoPlayerPr
167175
subtitleUrl,
168176
first,
169177
last,
178+
fullscreenPlayerIndex,
179+
setFullscreenPlayerIndex,
170180
selectCurrentlyAtInSeconds,
171181
selectPreviewTriggered,
172182
selectClickTriggered,
@@ -404,10 +414,13 @@ export const VideoPlayer = React.forwardRef<VideoPlayerForwardRef, VideoPlayerPr
404414
},
405415
});
406416

417+
const shouldHide = fullscreenPlayerIndex !== undefined && fullscreenPlayerIndex !== dataKey;
418+
407419
const videoPlayerWrapperStyles = css({
420+
position: "relative", // For fullscreen buttons
408421
height: "100%",
409422
width: "100%",
410-
display: "flex",
423+
display: shouldHide ? "none" : "flex",
411424

412425
// For single video, center!
413426
...(first && last) && { justifyContent: "center" },
@@ -420,6 +433,9 @@ export const VideoPlayer = React.forwardRef<VideoPlayerForwardRef, VideoPlayerPr
420433

421434
// For multi videos, in between, fit content and center!
422435
...(!first && !last) && { justifyContent: "center", flexBasis: "fit-content" },
436+
437+
// If fullscreen, treat like single video
438+
...fullscreenPlayerIndex !== undefined && { justifyContent: "center" },
423439
});
424440

425441
const render = () => {
@@ -444,6 +460,19 @@ export const VideoPlayer = React.forwardRef<VideoPlayerForwardRef, VideoPlayerPr
444460
config={playerConfig}
445461
disablePictureInPicture
446462
/>
463+
<button css={[basicButtonStyle(theme), css({
464+
position: "absolute",
465+
bottom: "10px",
466+
right: "10px",
467+
})]}
468+
onClick={() => {
469+
if (fullscreenPlayerIndex === undefined) {
470+
setFullscreenPlayerIndex(dataKey);
471+
} else {
472+
setFullscreenPlayerIndex(undefined);
473+
}
474+
}}
475+
><LuFullscreen /></button>
447476
</div>
448477
);
449478
} else {

0 commit comments

Comments
 (0)