我正在尝试通过 PHP 输出 mp4 视频文件。
当通过 Flash 播放器(例如 flowplayer)使用它时,它工作得很好。
但是当我尝试将它用作 html5 视频标签的源或直接调用 php 文件时,它不起作用。
我使用的代码如下:
$filesize = filesize($file);
header("Content-Type: video/mp4");
if ( empty($_SERVER['HTTP_RANGE']) )
{
header("Content-Length: $filesize");
readfile($file);
}
else //violes rfc2616, which requires ignoring the header if it's invalid
{
rangeDownload($file);
}
and rangeDownload
函数来自http://mobiforge.com/developing/story/content-delivery-mobile-devices http://mobiforge.com/developing/story/content-delivery-mobile-devices附录 A。
即使我使用Content-Range
标头(Content-Range:bytes 0-31596111/31596112
),它一直停留在下载 30.13 MB 的视频上。
最后我找到了让它发挥作用的方法
header("Content-Type: $mediatype");
if ( empty($_SERVER['HTTP_RANGE']) )
{
header("Content-Length: $filesize");
$fh = fopen($file, "rb") or die("Could not open file: " .$file);
# output file
while(!feof($fh))
{
# output file without bandwidth limiting
echo fread($fh, $filesize);
}
fclose($fh);
}
else //violes rfc2616, which requires ignoring the header if it's invalid
{
rangeDownload($file);
}
它在 php 文件和 html5 视频标签内部的直接链接中工作。
但为了在 Flowplayer 中工作(也许在其他 flash/html5 播放器中),您需要添加 mp4 扩展名(例如 view.php?id=XXX&file=type.mp4)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)