mp3list.php
· 1.7 KiB · PHP
Raw
<?php
$arr = array();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS)) as $item => $file) {
$arr[] = $item;
}
sort($arr);
?>
<html>
<head>
<style>
div.filelist {
overflow-y: scroll;
height: 90%;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var audio = document.createElement('audio');
$(window).load(function() {
audio.setAttribute('src', '');
audio.setAttribute('controls', 'controls');
audio.setAttribute('id', 'audio');
$('body').prepend(audio);
audio.load();
audio.addEventListener("ended", function () {
if (document.getElementById('autoplay').checked) {
playRandom();
}
});
if (window.location.hash != "" || window.location.hash != "#") {
set_src(window.location.hash.substring(1));
}
});
function playRandom() {
try {
var list = $('ul').find('li');
set_src($(list[Math.floor(Math.random()*list.length)]).find('a')[0].innerHTML);
} catch (err) {
playRandom();
}
}
function set_src(filename) {
audio.setAttribute('src', filename);
audio.load();
audio.play();
window.location.hash = filename;
return false;
}
</script>
</head>
<body>
<a href="#" onclick="playRandom(); return false;">Random</a><form><input type="checkbox" name="autoplay" id="autoplay" checked>Autoplay
<div class="filelist">
<ul>
<?php
foreach($arr as $item) {
if (mime_content_type($item) == "audio/mpeg") {
$item = substr($item, 2); ?>
<li><a href="#<?php echo $item; ?>" onClick="return set_src('<?php echo $item; ?>');"><?php echo $item; ?></a></li>
<?php } }
?>
</ul>
</div>
</body>
</html>
| 1 | <?php |
| 2 | $arr = array(); |
| 3 | foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS)) as $item => $file) { |
| 4 | $arr[] = $item; |
| 5 | } |
| 6 | sort($arr); |
| 7 | ?> |
| 8 | <html> |
| 9 | <head> |
| 10 | <style> |
| 11 | div.filelist { |
| 12 | overflow-y: scroll; |
| 13 | height: 90%; |
| 14 | } |
| 15 | </style> |
| 16 | <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> |
| 17 | <script> |
| 18 | var audio = document.createElement('audio'); |
| 19 | |
| 20 | $(window).load(function() { |
| 21 | audio.setAttribute('src', ''); |
| 22 | audio.setAttribute('controls', 'controls'); |
| 23 | audio.setAttribute('id', 'audio'); |
| 24 | $('body').prepend(audio); |
| 25 | audio.load(); |
| 26 | audio.addEventListener("ended", function () { |
| 27 | if (document.getElementById('autoplay').checked) { |
| 28 | playRandom(); |
| 29 | } |
| 30 | }); |
| 31 | if (window.location.hash != "" || window.location.hash != "#") { |
| 32 | set_src(window.location.hash.substring(1)); |
| 33 | } |
| 34 | }); |
| 35 | |
| 36 | function playRandom() { |
| 37 | try { |
| 38 | var list = $('ul').find('li'); |
| 39 | set_src($(list[Math.floor(Math.random()*list.length)]).find('a')[0].innerHTML); |
| 40 | } catch (err) { |
| 41 | playRandom(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | function set_src(filename) { |
| 46 | audio.setAttribute('src', filename); |
| 47 | audio.load(); |
| 48 | audio.play(); |
| 49 | window.location.hash = filename; |
| 50 | return false; |
| 51 | } |
| 52 | </script> |
| 53 | </head> |
| 54 | <body> |
| 55 | <a href="#" onclick="playRandom(); return false;">Random</a><form><input type="checkbox" name="autoplay" id="autoplay" checked>Autoplay |
| 56 | <div class="filelist"> |
| 57 | <ul> |
| 58 | <?php |
| 59 | foreach($arr as $item) { |
| 60 | if (mime_content_type($item) == "audio/mpeg") { |
| 61 | $item = substr($item, 2); ?> |
| 62 | <li><a href="#<?php echo $item; ?>" onClick="return set_src('<?php echo $item; ?>');"><?php echo $item; ?></a></li> |
| 63 | <?php } } |
| 64 | ?> |
| 65 | </ul> |
| 66 | </div> |
| 67 | </body> |
| 68 | </html> |
| 69 |