Last active
January 15, 2021 05:31
-
-
Save batica81/520a49272595bc6a958a1f3493a74dee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Makes playable album out of video files in a folder. Somewhat responsive.
TODO: