- Жена, я такой умный - бежал за автобусом и сэкономил 40 рублей!
- Дурень ты! Бежал бы за такси – сэкономил бы 5 тысяч!
function sendHeaders($size, $time, $is_partial, $begin, $end) {
header('Content-Type: audio/mpeg');
header('Cache-Control: no-cache, public, must-revalidate, max-age=0');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: inline;filename="test.mp3"');
header("Last-Modified: $time");
header('Pragma: no-cache');
header("Accept-Ranges: bytes 0-$size");
if ($is_partial) {
if ($end - $begin < 1) {
header("Content-Range: bytes */$size");
header('HTTP/1.1 416 Range Not Satisfiable');
exit;
}
header('HTTP/1.1 206 Partial Content');
header("Content-Range: bytes $begin-$end/$size");
header('Content-Length:' . (($end - $begin) + 1));
} else {
header('Content-length: '.$size);
header('HTTP/1.1 200 OK');
}
}
<audio id="player"></audio>
<ul id="playlist">
<li data-src="https://freesound.org/data/previews/447/447951_4716066-lq.mp3">tarck1</li>
<li data-src="https://freesound.org/data/previews/447/447896_7020227-lq.mp3">tarck2</li>
<li data-src="https://freesound.org/data/previews/447/447949_9080507-lq.mp3">tarck3</li>
</ul>
<script>
player.addEventListener("canplay", myAutplay);
player.addEventListener("canplaythrough", myAutplay);
function myAutplay () {
player.play();
}
playlist.addEventListener('click', function(evt) {
const track = evt.target.closest('li[data-src]');
if (track) {
player.src = track.dataset.src;
}
});
</script>