I have a Website with a html video with the default controls. To be able to show a div above the fullscreen video I followed this tutorial and created an outer div which contains the video and the div I want to show above.
Now I have the Problem that the Fullscreeen button of the default controls of the video still makes only the video fullscreen and not the parent div.
I tried to hook my custom fullsceen logic to the fullscreenchange
-Event, but that did not work because of
Request for fullscreen was denied because Element.requestFullscreen() was not called from inside a short running user-generated event handler.
Is there a possibility to catch a click event on that button?
I am using Firefox on Ubuntu 22.4
Here a demo html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Video div demo</title>
</head>
<body>
<div id="video-div" style="height: 80%; width: 100%;">
<video
id="video"
src="https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_10mb.mp4"
playsinline
preload="metadata"
controls
style="width: 100%; height: 100%"
>
</video>
<button
style="position: absolute; bottom: 2rem; right: 2rem; z-index: 0; background: #33334d; padding: 2rem;"
onclick="toggle_fullscreen()"
>
Toggle Fullscreen
</button>
</div>
</body>
<script>
document.getElementById("video").addEventListener('fullscreenchange', toggle_fullscreen)
function toggle_fullscreen(){
let video_div = document.getElementById("video-div");
if (document.fullscreenElement === null) {
video_div.requestFullscreen();
} else {
document.exitFullscreen();
}
}
</script>
</html>
By clicking the "Toggle Fullscreen" Button the parent div is made fullscreen, but the event handler for the fullscreenchange event when using the fullscreen button of the default video-controls does not work.