Last active 1440820623

Produce list of MP3 files in current and sub directories, playable by clicking

Revision 1382e01a61a5e114af6cf66ee434fab7ab025d51

mp3list.php Raw
1<?php
2function load_addon($filename) {
3 if (file_exists($filename)) {
4 include $filename;
5 }
6}
7$arr = array();
8foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS)) as $item => $file) {
9 $arr[] = $item;
10}
11sort($arr);
12?>
13<html>
14<head>
15<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
16<style>
17div.filelist {
18 overflow-y: scroll;
19 height: 90%;
20}
21</style>
22<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
23<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
24<script>
25
26var audio = document.createElement('audio');
27
28function playRandom() {
29 try {
30 var list = $('ul').find('li');
31 set_src($(list[Math.floor(Math.random()*list.length)]).find('a')[0].innerHTML);
32 } catch (err) {
33 playRandom();
34 }
35}
36
37function set_src(filename) {
38 audio.setAttribute('src', filename);
39 audio.load();
40 audio.play();
41 window.location.hash = filename;
42 return false;
43}
44
45function setVolume(volume) {
46 audio.volume = volume;
47}
48
49$(window).load(function() {
50 $("#volume").slider({
51 min: 0,
52 max: 100,
53 value: (audio.volume) * 100,
54 range: "min",
55 animate: true,
56 slide: function(event, ui) {
57 setVolume((ui.value) / 100);
58 }
59 });
60 audio.setAttribute('src', '');
61 audio.setAttribute('controls', 'controls');
62 audio.setAttribute('id', 'audio');
63 $('form').prepend(audio);
64 audio.load();
65 audio.addEventListener("ended", function () {
66 if (document.getElementById('autoplay').checked) {
67 playRandom();
68 }
69 });
70 if (window.location.hash != "" || window.location.hash != "#") {
71 set_src(window.location.hash.substring(1));
72 }
73});
74</script>
75</head>
76<body>
77<form onsubmit="return false;">
78 <input type="button" onclick="playRandom(); return false;" value="Random">
79 <input type="checkbox" name="autoplay" id="autoplay" checked>Autoplay
80</form>
81<div id="volume" style="width: 25%"></div>
82<div class="filelist">
83<ul>
84<?php
85foreach($arr as $item) {
86 if (mime_content_type($item) == "audio/mpeg") {
87 $item = substr($item, 2); ?>
88 <li><a href="#<?php echo $item; ?>" onClick="return set_src('<?php echo $item; ?>');"><?php echo $item; ?></a></li>
89<?php } }
90?>
91</ul>
92</div>
93</body>
94</html>
95