Skip to content

Instantly share code, notes, and snippets.

@batica81
Last active January 15, 2021 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save batica81/520a49272595bc6a958a1f3493a74dee to your computer and use it in GitHub Desktop.
Save batica81/520a49272595bc6a958a1f3493a74dee to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Media player</title>
<style type="text/css">
body {
background-color: lightgrey;
}
.videoWrapper {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.video, .audio {
text-align: center;
display: flex;
max-width: 300px;
flex-direction: column;
}
.videoTitle {
max-width: 300px;
font-weight: 700;
padding: 10px;
overflow: hidden;
text-overflow: ellipsis;
}
video {
max-width: 300px;
}
</style>
</head>
<body>
<?php
echo "<div class='videoWrapper'>";
//Name of our directory
$dir_name ='.thumbs';
//Check if the directory with the name already exists
if (!is_dir($dir_name)) {
//Create our directory if it does not exist
mkdir($dir_name);
// echo "Directory created";
}
$dir = '.';
$thumbs_dir = './.thumbs/';
$files1 = scandir($dir);
$thumbsArray = scandir($thumbs_dir);
$second = 1;
$thumbSize = '300x200';
foreach ($files1 as $key => $value) {
if (explode("/", mime_content_type($files1[$key]))[0] == "video") {
if (!in_array($files1[$key].".jpg", $thumbsArray)) {
shell_exec("ffmpeg -y -i ".escapeshellarg($files1[$key])." -vframes 1 -an -s ".$thumbSize." -ss 5 ".escapeshellarg($thumbs_dir.$files1[$key]).".jpg");
}
echo "<div class='video'>";
echo "<video controls preload='none' poster='".rawurlencode($thumbs_dir.$files1[$key]).".jpg'>";
echo "<source src=".rawurlencode($files1[$key])."></video>";
echo "<div class='videoTitle'>".$files1[$key]."</div>";
echo "</div>";
}
if (explode("/", mime_content_type($files1[$key]))[0] == "audio") {
echo "<div class='audio'>";
echo "<audio controls>";
echo "<source src=".$files1[$key]."></audio>";
echo "<h3>".$files1[$key]."<h3>";
echo "</div>";
}
}
echo "</div>";
?>
</body>
</html>
@batica81
Copy link
Author

batica81 commented Jan 7, 2020

Makes playable album out of video files in a folder. Somewhat responsive.
TODO:

  • Design
  • VLC (deep) linking
  • Pagination

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment