我有一个php文件,在那里我按各方下载一个flv文件,如下所示:
header('Accept-Ranges: bytes');
header('Content-Type: '.$mime_type);
header('Connection: keep-alive');
header ("Content-Length: " . $length);
header('Content-Transfer-Encoding: binary');
header ("Content-Disposition: attachment; filename=file.flv");
$fd = fopen($url, "r");
while(!feof($fd))
{
echo fread($fd, 4096);
ob_flush();
}
然后这个视频正在我的网页上播放使用视频JS:
<body>
<video id="video1" class="video-js vjs-default-skin" poster="http://video-js.zencoder.com/oceans-clip.png" width="640" height="480"
data-setup='{"loadingSpinner": false, "controls" : true, "autoplay" : true, "preload" : "auto"}'>
<source src="videos.php" type="video/x-flv">
</video>
</body>
但是,当我将时间显示视频滚动到1:12:14时,时间计数器停止,视频错误地显示在00:03:14(但指针仍显示在1:12:14)。
我想修复这个错误-如果文件没有加载到1:12:14-播放器应该阻止更改时间显示。
我该怎么做?
当您快速点击视频播放器时,浏览器将取消现有请求,只对文件。此新请求中存在"范围"标头。在这种情况下,服务器必须以状态代码206进行响应(部分内容),并包括"内容范围"标题。
if (isset($_SERVER['HTTP_RANGE']))
{
// extract the range string
list ($units, $range) = explode ("=", $_SERVER['HTTP_RANGE']);
list ($firstByte, $lastByte) = explode ("-", $range);
$length = $lastByte - $firstByte + 1; // Calculate a new content length
// seek forward on the file
fseek ($fd, $firstByte);
// headers to return for partial content
header ("HTTP/1.1 206 Partial Content");
header ("Content-Range: bytes $firstByte-$lastByte/$size");
header ("Content-Length: $length");
}
参见"14.35范围":http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html