Skip to content

Commit 62ce567

Browse files
committed
Fix fullscreen for Safari
This was written by @ferishili, many thanks! Fixes an issue where the video players would not show up IN SAFARI, leaving small empty boxes in their place. Only after clicking the full screen button a few times would the videos then show up. This fixes the issue by toggling the fullscreen button ourselves via code. We also confine this toggling to Safari, so that people who use reasonable browsers are not affected by any brief visual glitches this may result in.
1 parent b3cc5c7 commit 62ce567

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/main/VideoPlayers.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { backgroundBoxStyle, basicButtonStyle } from "../cssStyles";
4040
import { BaseReactPlayerProps } from "react-player/base";
4141
import { ErrorBox } from "@opencast/appkit";
4242
import { LuFullscreen } from "react-icons/lu";
43+
import { isSafari } from "react-device-detect";
4344

4445
const VideoPlayers: React.FC<{
4546
refs?: React.MutableRefObject<(VideoPlayerForwardRef | null)[]>,
@@ -420,10 +421,37 @@ export const VideoPlayer = React.forwardRef<VideoPlayerForwardRef, VideoPlayerPr
420421

421422
const shouldHide = fullscreenPlayerIndex !== undefined && fullscreenPlayerIndex !== dataKey;
422423

424+
// Because of Safari and the fact that it is not able to read and occupy based on rendered aspect ratio,
425+
// We need to toggle the display, in order for Safari to update itself!
426+
const initialVideoPlayerWrapperDisplay = isSafari ? "none" : "flex";
427+
const [videoPlayerWrapperDisplay, setVideoPlayerWrapperDisplay] = useState(initialVideoPlayerWrapperDisplay);
428+
429+
useEffect(() => {
430+
if (ready && isSafari) {
431+
const timeout = setTimeout(() => {
432+
setVideoPlayerWrapperDisplay("flex");
433+
}, 10);
434+
return () => clearTimeout(timeout);
435+
}
436+
}, [ready]);
437+
438+
// Watch fullscreenPlayerIndex and toggle display briefly, in order for Safari to update itself!
439+
useEffect(() => {
440+
if (fullscreenPlayerIndex !== undefined && isSafari) {
441+
setVideoPlayerWrapperDisplay("none");
442+
const timeout = setTimeout(() => {
443+
setVideoPlayerWrapperDisplay("flex");
444+
}, 10);
445+
return () => clearTimeout(timeout);
446+
}
447+
}, [fullscreenPlayerIndex]);
448+
423449
const videoPlayerWrapperStyles = css({
424450
height: "100%",
425451
width: "100%",
426-
display: shouldHide ? "none" : "flex",
452+
display: shouldHide ? "none" : videoPlayerWrapperDisplay,
453+
454+
flexGrow: "1",
427455

428456
// For single video, center!
429457
...(first && last) && { justifyContent: "center" },
@@ -450,7 +478,7 @@ export const VideoPlayer = React.forwardRef<VideoPlayerForwardRef, VideoPlayerPr
450478
<ReactPlayer url={url}
451479
// css={[backgroundBoxStyle(theme), reactPlayerStyle]} // moved to wrapper
452480
ref={ref}
453-
width="unset"
481+
width="100%"
454482
height="100%"
455483
playing={isPlaying}
456484
volume={volume}

0 commit comments

Comments
 (0)