iOS开发记录|iOS 关于Safari浏览器和Chrome浏览器Video标签的区别

Safari



GET /haoyun-web/fdfs/viewFdfsFile.action?groupName=group1&fileId=M00/00/05/wKgB8llDiPyAWf21AAL5k9M1ds4632.mp4 HTTP/1.1
Host 183.134.110.234:18080
Cookie JSESSIONID=306cc3b9-4428-4624-b8ad-5bb331187ced; sdktoken=3b6ccb1f39b0c43b4c644b9184699714; uid=user_100; yxAccount=user_91
X-Playback-Session-Id D91FBAEA-2E94-4984-B26A-C0FC8C5E4F5B
Range bytes=0-1
Accept */*
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4
Accept-Language zh-cn
Accept-Encoding identity
Connection keep-alive
Chrome
GET /haoyun-web/fdfs/viewFdfsFile.action?groupName=group1&fileId=M00/00/05/wKgB8llDiPyAWf21AAL5k9M1ds4632.mp4 HTTP/1.1
Host 183.134.110.234:18080
Accept-Encoding identity; q=1, *; q=0
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Accept */*
Referer http://www.runoob.com/try/try.php?filename=tryhtml5_video
Accept-Language zh-CN,zh; q=0.8,en; q=0.6
Cookie JSESSIONID=189317e9-462f-475d-9a09-e9f607e42bfc; JSESSIONID.7178883c=kc1daruvzmv16tltjdtz7ybe; yxAccount=user_91; uid=user_100; sdktoken=3b6ccb1f39b0c43b4c644b9184699714
Range bytes=0-194962

从中我们可以看出Safari默认range为 bytes=0-1,而Chrome则是 bytes=0-194962 safari多了个keep-alive 而对于safari来说,他不是一次性请求全部文件的(不论osx还是ios),一般首先会请求0-1字节,这个写在request header的"range"字段中: range:'bytes=0-1' 如果是想要传输视频, 必须要解析range字段,然后按照range字段的要求返回对应的数据,同时response header至少要包含三个字段:"Content-Type", "Content-Range", "Content-Length" "Content-Type"必需明确指定视频格式,有"video/mp4", "video/ogg", "video/mov"等等,网上可以查到。 "Content-Range"格式是 "bytes -/",其中start和end必需对应request header里的range字段,total是文件总大小,不是返回的数据长度 "Content-Length"指定返回的二进制长度 所以想要在Safari上播放需要服务端返回 Content-Range Content-Length
【iOS开发记录|iOS 关于Safari浏览器和Chrome浏览器Video标签的区别】其实也就是将fastfds的路径用ngix代理改成真正的文件地址即可

    推荐阅读