Tom Marthenal
Tom Marthenal

Reputation: 3146

Why won't Chrome or Safari properly play my MP3?

I have a web application running on Glassfish. The application is written in Java using Servlets.

The application allows you to upload files and get a direct link to that file.

For some reason, Safari and Chrome (possibly other browsers) have issues playing MP3 files (and other audio/video files) uploaded to this application.

An example uploaded MP3: http://uploads.graalcenter.org/upload/test.mp3

Sometimes, Safari will load the file and play it correctly, but most of the time it either stays on "Loading..." forever, or starts playing for a few seconds and then stops downloading it.

My browser is sending these request headers:

GET http://uploads.graalcenter.org/upload/test.mp3 HTTP/1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7) AppleWebKit/535.1+ (KHTML, like Gecko) Version/5.1 Safari/534.48.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Referer: http://uploads.graalcenter.org/info/test.mp3
Cache-Control: max-age=0

My server is responding with these response headers:

HTTP/1.1 200 OK
Date: Sun, 31 Jul 2011 02:02:03 GMT
X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.2-b06 Java/Sun Microsystems Inc./1.6)
Content-Length: 1137602
Server: GlassFish Server Open Source Edition 3.2-b06
Content-Type: audio/mpeg
Accept-Ranges: none

For comparison, I have uploaded the same file to an Apache server here.

The server responds with these headers:

HTTP/1.1 200 OK
Date: Sun, 31 Jul 2011 02:06:56 GMT
Connection: Keep-Alive
Content-Length: 1137602
Last-Modified: Sun, 31 Jul 2011 02:05:57 GMT
Server: Apache
Etag: "1aa08001-115bc2-4a953f48b6b40"
Content-Type: audio/mpeg
Accept-Ranges: bytes
Keep-Alive: timeout=2, max=100

The file plays correctly.

The only difference I can see is that my application does not accept range requests, but this shouldn't cause any issues, should it?

If I download the MP3 from my web application via curl, it has the same MD5 hash, so it's not corrupting the MP3 in any way.

Does anybody have any idea what might be causing the MP3 to not play correctly?

Upvotes: 2

Views: 2031

Answers (1)

Tom Marthenal
Tom Marthenal

Reputation: 3146

It seems like the problem was AppleCoreMedia, the plugin which handles audio, doesn't work correctly when not using range data. I wouldn't make the leap of blaming it on Apple, as it's entirely possible I made some mistake, but I ended up implementing the HTTP Range header and the it now works every time.

Upvotes: 0

Related Questions