跳至主要内容

解决iPhone无法播放站点提供的MP3的问题

正在开发的web站点提供语音文件给用户播放,发现iPhone 在播放MP3文件的时候遇到了一些问题,而从其他一些类似网站上下载的MP3文件却没有遇到这个问题。

第一直觉是MIME类型不对,但是比较了一下,都是一样的。iPhone里面点击MP3的连接之后会自动使用QuickTime播放器打开,然而QT直接弹出无法识别该链接……


经过一番搜索,终于在Google的iPhoneWebDev论坛上找到了一个很有用的帖子:

[quote] 
Configure Your Server
HTTP servers hosting media files for iPhone must support byte-range
requests, which iPhone uses to perform random access in media
playback. (Byte-range support is also known as content-range or
partial-range support.) Most, but not all, HTTP 1.1 servers already
support byte-range requests.
If you are not sure whether your media server supports byte-range
requests, you can open the Terminal application in Mac OS X and use
the curl command-line tool to download a short segment from a file on
the server:
curl -range 0-99http://example.com/test.mov-o/dev/null
If the tool reports that it downloaded 100 bytes, the media server
correctly handled the byte-range request. If it downloads the entire
file, you may need to update the media server. For more information on
curl, see Mac OS X Man Pages.
Ensure that your HTTP server sends the correct MIME types for movie
family file suffixes shown in the following table.
File name suffix MIME type
.mov video/quicktime
.mp4 video/mp4
.m4v video/x-m4v
.3gp video/3gpp
Be aware that iPhone supports movies greater than 2 GB. However, some
older web servers are not able to serve files this large. Apache 2
supports downloading files greater than 2GB.
RTSP is not supported.
[/quote]


原来是要在Web Host上支持Content-Range的选择,本来Apache和Tomcat 5.5的HTTP1.1实现是默认支持该Request Header的,刚好Servlet中绕过了Default Servlet的控制,自行实现了读文件并下发的功能,于是导致了这个问题。

评论