gpt4 book ai didi

php - 在 Google Chrome 中通过 PHP 传送 MP4 视频失败

转载 作者:技术小花猫 更新时间:2023-10-29 12:34:53 27 4
gpt4 key购买 nike

我目前正在尝试通过用于控制视频访问的 PHP 脚本传送 MP4 视频以用于 HTML5 视频(使用 video-js)。经过一些研究,在 stackoverflow article found here 的帮助下,我能够使它正常工作。 .如果我导航到 PHP 脚本,我可以像在 Firefox、Safari 和 IE 中通过绝对路径(例如 localhost/myvideo.mp4 而不是 localhost/myscript.php)查看视频一样查看视频。我的问题出在 Google Chrome 浏览器上,它只显示一个黑屏,中间有一个小型媒体播放器,什么也不做。

我确实尝试使用快速重写,例如路由到 PHP 脚本的 localhost/avideo.mp4,但不幸的是,这并没有改变任何东西。

这是我的脚本:

if (is_file($uri)) {
header('Content-Type: video/mp4');
if (isset($_SERVER['HTTP_RANGE'])) {
$this->rangeDownload($uri);
exit;
} else {
header("Content-Length: ".filesize($uri));
$this->readfile_chunked($uri);
exit;
}
} else {
//error
}

rangeDownload 方法直接取自 this link 的附录 A正如前面提到的 stackoverflow 文章中所建议的那样。

最佳答案

也许问题出在 URL(更具体地说,是扩展名)。通常,您会使用 Content-Disposition header ,但我知道在向手机传送内容时这是不可取的。

尝试使用 localhost/myscript.php/myvideo.mp4

It is important not to use the "Content-Disposition" HTTP header, since some phones refuse to accept content when using it. By including the filename on the URL, you will trick the phone to think it's a real file and to accept it.

Now, when you send the download URL to the customer, you don't normally know yet what device the customer has, so you don't know what file formats the device will support. Therefore, you can't include the filename on that URL, and once again, you will need an intermediate download page. Once more, we will use a URL like:

http://wap.mydomain.tld/get.php/123456abcdef

This time, when the customer connects to download the content, the get.php script will not create a temporary file, but point to another script which streams the file contents. Supposing the resultant content to download will be "image.jpg", the intermediate download page could point the customer to a URL like:

http://wap.mydomain.tld/download.php/123456abcdef/image.jpg

来自 ( http://mobiforge.com/developing/story/content-delivery-mobile-devices )

关于php - 在 Google Chrome 中通过 PHP 传送 MP4 视频失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11431778/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com