jgtrosh

web music

May 11th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.98 KB | None | 0 0
  1. <?
  2.     $d = ".";
  3.     if (isset($_POST["d"]) && $_POST["d"] != "") $d = $_POST["d"];
  4. ?>
  5. <html>
  6.     <head>
  7.         <style type="text/css">
  8.             form { margin: 0; }
  9.             a.audio { color: green; }
  10.             a.dir { color: red; }
  11.             table.list td { width: 300px; height: 10px; border: solid black 1px;}
  12.         </style>
  13.         <script type="text/javascript">
  14.             var songs = [<? foreach (glob("$d/*.mp3") as $song) {echo "\"$song\",";}?>];
  15.             var playlist = songs;
  16.             var player;
  17.             function loaded() {
  18.                 player = document.getElementById("player");
  19.                 player.addEventListener("ended", PlayNext);
  20.             }
  21.             function play(entry) {
  22.                 playlist = songs.slice(entry);
  23.                 //buildSources();
  24.                 document.getElementById("nowplaying").innerHTML = playlist[0];
  25.                 player.src = playlist[0];
  26.                 player.play();
  27.             }
  28.             function PlayNext() {
  29.                 playlist = playlist.slice(1);
  30.                 //buildSources();
  31.                 if (playlist.length > 0) {
  32.                     document.getElementById("nowplaying").innerHTML = playlist[0];
  33.                     player.src = playlist[0];
  34.                     player.play();
  35.                 }
  36.             }
  37.             function buildSources() {
  38.                 player.innerHTML = "";
  39.                 for (i=0;i<playlist.length;i++) {
  40.                     player.innerHTML += "<source src='" + playlist[i] + "'>";
  41.                 }
  42.             }
  43.         </script>
  44.     </head>
  45.     <body onLoad="loaded()" style="width: 200%;">
  46.         <form action="index.php" method="POST">
  47.             <input type="text" name="d" value="<? echo "$d"; ?>" size="150">
  48.         </form>
  49.         <form method='POST' action='index.php'><input type='hidden' name='d' value='<? echo preg_replace("/\/[^\/]*$/", "", $d); ?>'><input type='submit' value='..'></form>
  50. <? if ($handle = opendir("$d")) {
  51.     $entries = array();
  52.     while (false !== ($entry = readdir($handle))) {
  53.         if (substr($entry, 0, 1) != ".") {
  54.             $entries[] = $entry;
  55.         }
  56.     }
  57.     sort($entries);
  58. }
  59. ?>
  60.         <table id="container"><tr>
  61. <? $mp3c = 0;
  62.     $lentries = count($entries);
  63.     $col = 18;
  64.     for ($i=0;$col*$i<$lentries;$i++) {?>
  65.         <td style="width: 300px; vertical-align: top;"><table class="list" style="margin-bottom: 50px; width: 100%; border-collapse: collapse;">
  66. <?
  67.         for ($j=0;$j<$col;$j++) {
  68.             if ($col*$i+$j<$lentries) {
  69.                 echo "<tr><td>";
  70.                 $entry = $entries[$col*$i+$j];
  71.                 $ext = substr($entry, -4, 4);
  72.                 if ($ext == ".mp3") {
  73.                     echo "<a class='audio' id='$mp3c' href='#' onclick='play(this.id)'>$entry</a>";
  74.                     $mp3c++;
  75.                 } elseif (is_dir("$d/$entry")) {
  76.                     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>";
  77.                 } else {
  78.                     echo "<a href='$d/$entry'>$entry";
  79.                 }
  80.                 echo "</td></tr>";
  81.             }
  82.         }
  83.         echo "</td></table>\n";
  84.     }
  85. ?>
  86.         </tr></table>
  87.         <div style="position: fixed; bottom: 0; width: 90%; background-color: black; color: white; border-top: solid black 1px;">
  88.             <div id="nowplaying"><? echo "$d/"; ?></div>
  89.             <audio id="player" style="width: 100%;" onload="this.addEventListener('ended', PlayNext)" controls></audio>
  90.         </div>
  91.     </body>
  92. </html>
Advertisement
Add Comment
Please, Sign In to add comment