I'm about to make a simple survey where the users has to listen to some audio (about 20. sec of a song) ..
I use the HTML5 Audio tag to listen to the audio files.
My audio files is stored in a database in base64, and when I serve the audio i base64 decode.
Every time i load the MP3 url i get a HTTP status 206 or 416 - don't know if my headers is wrong, i have read lot of blogs and stackoverflow answers, but can't find the correct way to do it.
it works if i play the URL in VLC or iTunes but not when I try to load it in HTML Audio tag.
My PHP code
$buffer = base64_decode($res['binarydata']);
header("Content-Type: audio/mpeg");
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Content-Length: '.strlen($buffer);
header("Content-Disposition: inline; filename=test42.mp3");
header("Content-Transfer-Encoding: binary\n");
header('Connection: close');
echo $buffer;