<视频>可在其他浏览器中播放,但不能在 Safari 中播放 [英] <video> plays in other browsers, but not Safari

查看:51
本文介绍了<视频>可在其他浏览器中播放,但不能在 Safari 中播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的网站上有一个 MP4 视频;它在 IE9+、Firefox、Chrome 和 mac 上的 Chrome 中运行良好.但是,在 Safari 上,视频根本不播放 - 它确实触发了停滞"事件,然后没有加载任何内容.我会发布我们的 HTML,但我通过发现即使导航到原始 MP4 的 URL Safari 也不会播放它来进一步追踪问题.在本地下载并播放时,视频在 Quicktime 中运行良好.

最奇怪的部分是我们所有的开发人员,当我从我的开发计算机运行相关服务器时,可以让视频在 Safari 上运行.更何况,同一目录下的其他MP4文件也有类似的问题.这一直是我的关键,我一直在寻找视频从服务器传输的方式的任何细微差别 - 请求/响应标头、确切的文件大小等.

从 Chrome 复制的标题(因为 Safari 更难复制/粘贴)

接受:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8接受编码:gzip、deflate、sdch接受语言:en-US,en;q=0.8缓存控制:最大年龄= 0连接:保持连接DNT:1主持人:****************:8443用户代理:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36响应头接受范围:字节内容长度:44875102内容类型:视频/mp4;字符集=UTF-8日期:2014 年 12 月 30 日,星期二 21:11:51 GMTETag:W/"44875102-1419959755000"上次修改时间:2014 年 12 月 30 日,星期二 17:15:55 GMT服务器:Apache-Coyote/1.1

(另外,以防万一这让您想起一个旧问题;我知道 Windows 上的 Safari 已经死了很久了.这个问题发生在 OS X 上)

可能会有所帮助的新信息.我从我自己的网络服务器上获取了一个个人视频,该视频可以在有问题的 Safari 浏览器上运行,并将其下载到我们服务器的本地视频目录中.从那里,它遇到了与我们的其他视频相同的问题.这向我表明 MP4 本身可能无关紧要 - 这可能是我们的 Tomcat 7 网络服务器的某种服务器问题.我们确实正确注册了 Content-Types,这至少涵盖了基础知识,但我很好奇是否还有其他必要的部分.

更多信息:我最初没想到要提及这一点,但我们正在通过 HTTPS 连接加载我们的网页和视频.我们的大多数测试服务器都没有有效的证书,因此我们需要单击标准浏览器警告此服务器可能不是它所说的那样".我们现在正在研究如何在我们的所有服务器上拥有正确的证书.

解决方案

Safari 需要 webserver 支持 "范围"请求标头以播放您的媒体内容.

https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariWebContent/CreatingVideoforSafarioniPhone/CreatingVideoforSafarioniPhone.html#//apple_ref/doc/uid/TP40006514-SW6>

对于合法的范围";请求响应,您的网络服务需要返回状态代码206".

We have an MP4 video on our site; it plays fine in IE9+, Firefox, Chrome, and Chrome on mac. However, on Safari, the video doesn't play at all - it does trigger a "stalled" event and then nothing loads. I would post our HTML, but I traced the problem further by finding that Safari wouldn't play it even when navigating to the original MP4's URL. When downloaded and played locally, the video works fine in Quicktime.

The weirdest part of this is that of all our developers, I can get the video to work on Safari when I run the related server from my development computer. What's more, other MP4 files in the same directory have a similar problem. This has been the key to me, and I've been searching for any little difference in the way the videos transfer from the server - request/response headers, exact filesize, etc.

Headers copied from Chrome (only since Safari is harder to copy/paste from)

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
DNT:1
Host:*************:8443
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36

Response Headers
Accept-Ranges:bytes
Content-Length:44875102
Content-Type:video/mp4;charset=UTF-8
Date:Tue, 30 Dec 2014 21:11:51 GMT
ETag:W/"44875102-1419959755000"
Last-Modified:Tue, 30 Dec 2014 17:15:55 GMT
Server:Apache-Coyote/1.1

(Also, just in case this reminds you of an older issue; I'm aware Safari on Windows has been dead for ages. This issue is occurring on OS X)

EDIT: New info that might help a bit. I took a personal video from my own webserver, which was able to work from there on the problematic Safari browsers in question, and downloaded it to our server's local video directory. From there, it encounters the same issue as our other videos. This suggests to me that the MP4 itself may not matter - this is probably a server issue of some sort with our Tomcat 7 webserver. We do have the Content-Types registered correctly, which at least covers the basics, but I am curious if there are other necessary parts.

MORE INFO: I didn't think to mention this initially, but we are loading our webpages and videos over an HTTPS connection. Most of our test servers do not have valid certificates, and so we need to click through the standard browser warning that "This server might not be who it says". We are now looking into what it would take to have correct certificates on all our servers.

解决方案

Safari requires webserver to support "Range" request header in order to play your media content.

https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariWebContent/CreatingVideoforSafarioniPhone/CreatingVideoforSafarioniPhone.html#//apple_ref/doc/uid/TP40006514-SW6

For a legit "Range" request response, your webserve need to return status code "206".

这篇关于<视频>可在其他浏览器中播放,但不能在 Safari 中播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆