在safari浏览器中,视频播放不了,问题点在于视频本身。
1.必须在视频输出时,加rang请求头。
2.html5media.js亲测无效,不需要加,只要处理好第一点即可
上代码
一、视频输出
$total = filesize($filename);
if(isset($_SERVER['HTTP_RANGE'])) {
$range = str_replace('=','-',$_SERVER['HTTP_RANGE']);
$range = explode('-',$range);
if (isset($range[2]) && intval($range[2]) >0){
$end = trim($range[2]);
}else{
$end = $total-1;
}
$start = trim($range[1]);
$size = $end-$start+1;
header('Content-Length:'.$size);
header('Content-Range: bytes '.$start.'-'.$end.'/'.$total);
} else {
$size = $total;
header('Content-Length:'.$size);
header('Content-Range: bytes 0-'.($total-1).'/'.$total);
}
header('Accenpt-Ranges: bytes');
header('Content-Type: video/mpeg4');
$fp = fopen($filename,'rb+');
fseek($fp,$start);
while(!feof($fp)) {
print_r(fread($fp,$size));
flush();
ob_flush();
}
fclose($fp);
二、html展示
<!DOCTYPE HTML>
<html>
<body>
<video controls="controls">
<source src="一中php程序访问网址" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
</html>