Skip to content

Instantly share code, notes, and snippets.

@clouddueling
Created May 9, 2014 19:57
Show Gist options
  • Save clouddueling/723df7bf07a7e6dc49d1 to your computer and use it in GitHub Desktop.
Save clouddueling/723df7bf07a7e6dc49d1 to your computer and use it in GitHub Desktop.
AngularJS FileSystem Music Player
  1. Install PHP
  2. Create an index.php in the folder you want to play mp3's from.
  3. In your terminal navigate to that folder and run: php -S localhost:3333
  4. Go to http://codepen.io/clouddueling/full/atwke and your files should load.
<?php
if (isset($_GET['file'])) {
$filename = './' . $_GET['file'];
if (file_exists($filename)) {
header('Content-Type: audio/mpeg');
header('Content-Disposition: inline;filename="' . $filename . '.mp3"');
header('Content-length: ' . filesize($filename));
header('Cache-Control: no-cache');
header("Content-Transfer-Encoding: chunked");
readfile($filename);
}
return;
}
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
$dh = opendir('./');
while (false !== ($filename = readdir($dh))) {
if ($filename[0] == '.') {
continue;
}
$files[] = $filename;
}
sort($files);
echo json_encode($files);
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment