I have a MongoDB database with audio files stored in GridFS. HTML5 audio tag works with a link to a method that gets audio from MongoDB:
$file = $grid->findOne(array('_id' => new MongoId($id)));
header('Content-Length: ' . $file->file['length']);
header('Content-Type: ' . $file->file['file_type']);
header("Content-Disposition: filename=" . $file->file['filename']);
echo $file->getBytes();
All is good but one thing: I can’t use slidebar to skip through audio, it only plays from start to end.
Try adding an
Accept-Ranges = bytesheader. From http://html5doctor.com/html5-audio-the-state-of-play/:Also a
X-Content-Duration = length_in_secondsheader may help if the files are in ogg format. From https://developer.mozilla.org/en-US/docs/Configuring_servers_for_Ogg_media:Both of these headers help the browser to determine the audio’s duration before the file is fully downloaded so that seeking is possible, and the playhead can be positioned properly.