我使用 PHP 脚本在提供视频请求之前对其进行验证。该脚本在桌面上按预期工作,与 Safari 和 Chrome 一起使用。但是在 iOS 上,我的播放按钮坏了。
我确定视频已针对 iPhone/iPad 正确编码,因为当我直接访问它时,它会按预期工作。
相关的PHP代码:
$file_name = 'test-video.mp4';
$file_size = (string)(filesize($file_name));
header('Content-Type: video/mp4');
header('Content-Length: '.$file_size);
readfile_chunked($file_name);
exit;
(readfile_chunked()
类似于readfile()
但对于非常大的文件,可在 PHP 手册页的评论中找到:http: //php.net/manual/en/function.readfile.php。无论如何,test-video.mp4
只有 ~5 MB,即小于内存限制——在这种情况下,我实际上可以替换正常readfile()
并产生完全相同的行为。)
我test-video.mp4
直接访问时得到的标题是:
Accept-Ranges:bytes
Connection:Keep-Alive
Content-Length:5558749
Content-Type:video/mp4
Date:Sun, 27 Jun 2010 21:02:09 GMT
Etag:"1c04757-54d1dd-489944c5a6400"
Keep-Alive:timeout=10, max=30
Last-Modified:Tue, 22 Jun 2010 01:25:36 GMT
Server:Apache/2.2.15 (CentOS) mod_ssl/2.2.15 0.9.8l DAV/2 mod_auth_passthrough/2.1 FrontPage/5.0.2.2635
PHP 脚本的标头是:
Connection:Keep-Alive
Content-Disposition:inline; filename="test-video.mp4"
Content-Length:5558749
Content-Type:video/mp4
Date:Sun, 27 Jun 2010 21:03:32 GMT
Keep-Alive:timeout=10, max=15
Server:Apache/2.2.15 (CentOS) mod_ssl/2.2.15 0.9.8l DAV/2 mod_auth_passthrough/2.1 FrontPage/5.0.2.2635
X-Powered-By:PHP/5.2.13
我尝试了许多不同的标头排列,甚至将它们与直接请求中的标头完全匹配,但无济于事。
有没有人在 iOS 上通过 PHP 成功地提供 HTML5 视频?
[注意:我会尝试使用 X-Sendfile,但该站点位于共享主机上,访问权限非常有限。]
编辑:我读到 iOS 可能对文件扩展名很敏感,所以我尝试设置一个 RewriteRule 将 MP4 请求重写回我的原始 PHP 脚本,但这也无济于事。