A
Anonymous
Guest
Could someone possibly help me with some code for a video gallery?
Unfortunately, I am way out of my depth here, I'm passable at python, but html and the associated stuff is a mystery to me. I have the following code which works a treat provided all the files are in one folder, but the program I'm using saves everything in subfolders (which I cant change). The good thing about this is that it doesn't rely on any plugins / online java scripts etc... which is essential because there won't always be an internet connection. I have looked online and although I know what to do (a recursive search), I can't seem to adapt the code to work with this.
Any help would be brilliant, else I will be spending another night starring at the screen in vain.
Kind regards
Paul
Unfortunately, I am way out of my depth here, I'm passable at python, but html and the associated stuff is a mystery to me. I have the following code which works a treat provided all the files are in one folder, but the program I'm using saves everything in subfolders (which I cant change). The good thing about this is that it doesn't rely on any plugins / online java scripts etc... which is essential because there won't always be an internet connection. I have looked online and although I know what to do (a recursive search), I can't seem to adapt the code to work with this.
Any help would be brilliant, else I will be spending another night starring at the screen in vain.
Kind regards
Paul
Code:
<!DOCTYPE html>
<html>
<head>
<title>Simple PHP Video Gallery</title>
<link rel="stylesheet" type="text/css" href="2-theme.css">
</head>
<body>
<div id="vid-gallery"><?php
// (A) GET ALL VIDEO FILES FROM THE GALLERY FOLDER
$dir = __DIR__ . DIRECTORY_SEPARATOR . "gallery" . DIRECTORY_SEPARATOR;
$videos = glob($dir . "*.{webm,mp4,ogg}", GLOB_BRACE);
// (B) OUTPUT ALL VIDEOS
if (count($videos) > 0) { foreach ($videos as $vid) {
printf("<video src='gallery/%s'>preload=auto</video>", rawurlencode(basename($vid)));
}}
?></div>
<script>
window.addEventListener("DOMContentLoaded", function(){
for (let vid of document.querySelectorAll("#vid-gallery video")) {
// (A) CLICK ON THUMBNAIL TO GO FULLSCREEN
vid.addEventListener("click", function(){
if (!this.fullscreenElement) {
this.controls = true;
this.requestFullscreen();
}
});
// (B) EXIT FULLSCREEN MODE
vid.addEventListener("fullscreenchange", function(){
if (document.fullscreenElement == null) {
this.controls = false;
this.pause();
}
});
}
});
</script>
</body>
</html>