1

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;
pkdkk
  • 3,905
  • 8
  • 44
  • 69
  • 2
    Not an answer, but why are you storing the base64 encoded version of the file instead of just the binary data? – PeeHaa Aug 06 '15 at 07:58
  • Duplicate http://stackoverflow.com/questions/9627678/sending-mp3-file-through-php-to-be-used-with-the-audio-tag-of-html5-fails-in-the – PeeHaa Aug 06 '15 at 08:00
  • The errors are about requesting ranges which your script doesn't account for – PeeHaa Aug 06 '15 at 08:00
  • @PeeHaa even faster: just store the audio file path. – Absalón Valdés Aug 06 '15 at 08:10
  • 1
    Well imo it depends @absalon.valdes. There is something to say for storing it in the database instead. – PeeHaa Aug 06 '15 at 08:11
  • @pkdkk The response status codes have to come from your script or server somewhere. And, I don't see that in your script. Something is handling range requests... what is it? There isn't enough information here to debug your problem. You can simply ignore range requests (like your script is doing) and be just fine. – Brad Aug 07 '15 at 14:54

0 Answers0