Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- $d = ".";
- if (isset($_POST["d"]) && $_POST["d"] != "") $d = $_POST["d"];
- ?>
- <html>
- <head>
- <style type="text/css">
- form { margin: 0; }
- a.audio { color: green; }
- a.dir { color: red; }
- table.list td { width: 300px; height: 10px; border: solid black 1px;}
- </style>
- <script type="text/javascript">
- var songs = [<? foreach (glob("$d/*.mp3") as $song) {echo "\"$song\",";}?>];
- var playlist = songs;
- var player;
- function loaded() {
- player = document.getElementById("player");
- player.addEventListener("ended", PlayNext);
- }
- function play(entry) {
- playlist = songs.slice(entry);
- //buildSources();
- document.getElementById("nowplaying").innerHTML = playlist[0];
- player.src = playlist[0];
- player.play();
- }
- function PlayNext() {
- playlist = playlist.slice(1);
- //buildSources();
- if (playlist.length > 0) {
- document.getElementById("nowplaying").innerHTML = playlist[0];
- player.src = playlist[0];
- player.play();
- }
- }
- function buildSources() {
- player.innerHTML = "";
- for (i=0;i<playlist.length;i++) {
- player.innerHTML += "<source src='" + playlist[i] + "'>";
- }
- }
- </script>
- </head>
- <body onLoad="loaded()" style="width: 200%;">
- <form action="index.php" method="POST">
- <input type="text" name="d" value="<? echo "$d"; ?>" size="150">
- </form>
- <form method='POST' action='index.php'><input type='hidden' name='d' value='<? echo preg_replace("/\/[^\/]*$/", "", $d); ?>'><input type='submit' value='..'></form>
- <? if ($handle = opendir("$d")) {
- $entries = array();
- while (false !== ($entry = readdir($handle))) {
- if (substr($entry, 0, 1) != ".") {
- $entries[] = $entry;
- }
- }
- sort($entries);
- }
- ?>
- <table id="container"><tr>
- <? $mp3c = 0;
- $lentries = count($entries);
- $col = 18;
- for ($i=0;$col*$i<$lentries;$i++) {?>
- <td style="width: 300px; vertical-align: top;"><table class="list" style="margin-bottom: 50px; width: 100%; border-collapse: collapse;">
- <?
- for ($j=0;$j<$col;$j++) {
- if ($col*$i+$j<$lentries) {
- echo "<tr><td>";
- $entry = $entries[$col*$i+$j];
- $ext = substr($entry, -4, 4);
- if ($ext == ".mp3") {
- echo "<a class='audio' id='$mp3c' href='#' onclick='play(this.id)'>$entry</a>";
- $mp3c++;
- } elseif (is_dir("$d/$entry")) {
- echo "<form id='$entry' action='index.php' method='POST'><input type='hidden' name='d' value='$d/$entry'></form><a class='dir' href='#' onclick='document.getElementById(\"$entry\").submit()'>$entry/</a>";
- } else {
- echo "<a href='$d/$entry'>$entry";
- }
- echo "</td></tr>";
- }
- }
- echo "</td></table>\n";
- }
- ?>
- </tr></table>
- <div style="position: fixed; bottom: 0; width: 90%; background-color: black; color: white; border-top: solid black 1px;">
- <div id="nowplaying"><? echo "$d/"; ?></div>
- <audio id="player" style="width: 100%;" onload="this.addEventListener('ended', PlayNext)" controls></audio>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment