views:

797

answers:

3

I want use html5's new tag to play a wav file (currently only supported in FF.)

https://developer.mozilla.org/En/HTML/Element/Audio

I"m using php's readfile command to get the wav file off the hdd, and write it to the http response.

But its not working. The audio widget in firefox just has the loading animation running constantly.

The tag seems to be fine as I can put a different url in it's src/source and it works fine. I can use an tag and that downloads the file and it plays using Quicktime fine.

So I thinking perhaps its one/all of the content headers.

Using the FF Extension httpfox I can see these response headers arrive from the server:

(Status-Line)   HTTP/1.1 200 OK
Date    Mon, 12 Oct 2009 03:04:33 GMT
Server  securesauce
Cache-Control   private
Expires Mon, 26 Jul 1997 05:00:00 GMT
Pragma  private
Vary    Accept-Encoding
Content-Encoding    gzip
Content-Length  8217
Keep-Alive  timeout=15, max=100
Connection  Keep-Alive
Content-Type    audio/x-wav

So everything looks how I'd expect it to. The only headers I'm explicitly setting in the script (others are set elsewhere in the app) are:

Cache-Control   private
Pragma  private
Content-Type    audio/x-wav

When I tried a different wav file (random one off the internet) httpfox didn't list any response headers.

Because its a php file sending out the content, I can't just send no headers, as I'd have to at least send the content-type.

Any ideas?

Source excerpt:

header('Cache-Control: private');
header('Pragma: private');
header("Content-Type: $contentType");
readfile($filepath);
exit;
A: 

Have you tried the url of the audio file directly in your browser? If it contains an error or a warning that will make your header obsolete. and also try to open the audio file from the browser, see if it is correct.

Darkerstar
Thanks, yes, tried that, the file plays normally using quicktime. (Loading it directly is how I got the headers via httpfox.) I can also save the file and then play the file using Windows Media Player.
Redzarf
+2  A: 

Which formats and MIME types are supported by Mozilla is documented on their wiki. It doesn't look like the MIME type is your problem, but it's quite possible that this WAVE file isn't using the plain PCM audio which Firefox supports. WAVE can actually contain other formats like ADPCM, MP3 and whatnot. These may be supported by QuickTime, but there's no guarantee that it will play in a HTML5 browser. To be sure, try opening the file in a audio editor and saving it again as a WAVE PCM file.

foolip
Ah, thats it! The wav files are recorded by Asterisk in GSM610.
Redzarf
After an hours of dicking around with headers in my django project this put me on the right path! Kudos to you sir.
HurnsMobile
A: 

I had the same trouble sending an ogg audio file using php. Playing with the headers did not help.

Then I updated from firefox 3.5.2 to 3.5.4 - that fixed the problem.

ben