为什么 Chrome 或 Safari 无法正常播放我的 MP3?
我有一个在 Glassfish 上运行的 Web 应用程序。该应用程序是使用 Servlet 用 Java 编写的。
该应用程序允许您上传文件并获取该文件的直接链接。
由于某种原因,Safari 和 Chrome(可能是其他浏览器)在播放上传到此应用程序的 MP3 文件(和其他音频/视频文件)时出现问题。
上传的 MP3 示例:http://uploads.graalcenter.org/upload/test.mp3
有时,Safari 会加载文件并正确播放,但大多数时候它要么永远停留在“正在加载...”,要么开始播放几秒钟然后停止下载。
我的浏览器正在发送这些请求标头:
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
我的服务器正在使用这些响应标头进行响应:
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
为了进行比较,我已将相同的文件上传到 Apache 服务器 这里。
服务器使用以下标头进行响应:
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
文件正常播放。
我能看到的唯一区别是我的应用程序不接受范围请求,但这不会导致任何问题,不是吗?
如果我通过curl 从我的Web 应用程序下载MP3,它具有相同的MD5 哈希值,因此它不会以任何方式损坏MP3。
有谁知道可能导致 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎是 AppleCoreMedia(处理音频的插件)在不使用范围数据时无法正常工作。我不会将其归咎于 Apple,因为我完全有可能犯了一些错误,但我最终实现了 HTTP Range 标头,现在它每次都可以工作。
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.