mp3list.php
· 2.4 KiB · PHP
Raw
<?php
function load_addon($filename) {
if (file_exists($filename)) {
include $filename;
}
}
$arr = array();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS)) as $item => $file) {
$arr[] = $item;
}
sort($arr);
?>
<html>
<head>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<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 src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script>
var audio = document.createElement('audio');
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;
}
function setVolume(volume) {
audio.volume = volume;
}
$(window).load(function() {
$("#volume").slider({
min: 0,
max: 100,
value: (audio.volume) * 100,
range: "min",
animate: true,
slide: function(event, ui) {
setVolume((ui.value) / 100);
}
});
audio.setAttribute('src', '');
audio.setAttribute('controls', 'controls');
audio.setAttribute('id', 'audio');
$('form').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));
}
});
</script>
</head>
<body>
<form onsubmit="return false;">
<input type="button" onclick="playRandom(); return false;" value="Random">
<input type="checkbox" name="autoplay" id="autoplay" checked>Autoplay
</form>
<div id="volume" style="width: 25%"></div>
<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 | function load_addon($filename) { |
| 3 | if (file_exists($filename)) { |
| 4 | include $filename; |
| 5 | } |
| 6 | } |
| 7 | $arr = array(); |
| 8 | foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS)) as $item => $file) { |
| 9 | $arr[] = $item; |
| 10 | } |
| 11 | sort($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> |
| 17 | div.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 | |
| 26 | var audio = document.createElement('audio'); |
| 27 | |
| 28 | function 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 | |
| 37 | function set_src(filename) { |
| 38 | audio.setAttribute('src', filename); |
| 39 | audio.load(); |
| 40 | audio.play(); |
| 41 | window.location.hash = filename; |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | function 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 |
| 85 | foreach($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 |