tags:

views:

38

answers:

2

I am building a site that stores a few mp3 audio files in mySQL. At the moment only 5, so efficiency is not an issue at all.

CUrrently, I am still trying to make a cross browser/platform solution that will not require other file formats.

I have a PHP script that retrieves the mp3 binary data and sends the appropriate header to the browser. The files can then be retrieved by specifying the src of the audio element (whether it be audio or embed, or other) as follows: src="retrieve_audio.php?uniqueAudioID=[PHP variable identifying file]". The retrieve_audio php file take the database ID provided in the URL and retrieves the data, sends it with the header to the requesting page...

This works well for audio and embed tags in Safari. Works well for embed in IE 6, 7 and 8.

For some reason Safari calls it a stream -probably because the size of the file is not provided - and the controls don't allow for scrubbing the file regardless of tag used (audio or embed). IE appears to understand the length of the retrieved file although it is not explicitly given.

The real issue, though, is Firefox, Opera and Chrome. These do not appear to understand this at all. FIrefox shows a control for a few secs and then displays an X as in - I can't play this... I am aware of the issues with the tag in Firefox. It does the same with embed. Opera and Chrome just either display nothing or a blank white square.

Any suggestions?

I never thought I would have to wrestle with Firefox on something that works in IE!

Any input will be much appreciated.

M

A: 

try uploading the MP3s to your web server then storing the link to the MP3s in your Mysql database then just tell php to grab the link and echo out an html embed tag with the link as the src.

Patrick Gates
Prefer to keep the data and its related info in a database together. This way I can keep the mime type, file size, Title and any other info with the file in its record. Nothing to get out of sync and it allows my user to upload new files into the site keeping all that info (gathered by the upload code, except for the title, which is provided by the user) together with the file data.
Manca Weeks
A: 

I've had problems with Firefox before, it expects a Content-length HTTP header with pretty much everything.

You could try to find out the content length of the MP3 file using an SQL SELECT data, LENGTH(data) FROM ... and then set the HTTP header using header("Content-length: $lengthField");

HalfBrian
Thanks - you gave an idea that worked - didn't do exactly what you said - did supply a content-length header, but the info in it was instead stored with the file in the mySQL database and a field called file_size. Since the database content size won't change until next upload that made sense.This took care of FIrefox and Opera - Chrome still doesn't know what to do with the audio - I may just ignore that - unless someone has an idea how to fix...M
Manca Weeks