好吧,基本上我有一个项目要求视频对用户隐藏,同时仍能看到它们(通过使用php).这是我到目前为止所得到的:
video.php文件包含:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'path/to/movie.mp4');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$out = curl_exec($ch);
curl_close($ch);
header('Content-type: video/mp4');
header('Content-type: video/mpeg');
header('Content-disposition: inline');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($out));
echo $out;
exit();
?>
Run Code Online (Sandbox Code Playgroud)
并且应该显示的html文件正在使用html5.现在这里的事情......当我直接嵌入这个(不是)时它起作用.但它不适用于我的iPhone并且无法在标签中工作...如果我使用直接文件而不是php包装器,一切正常,在我的iPhone上也是如此...
所以我想我的问题是这样的:什么是正确的header()信息来完美复制可以通过iPhone和HMTL5流式传输的mp4?
解决方案源自:http://mobiforge.com/developing/story/content-delivery-mobile-devices
video.php文件:
<?php
$file = 'path/to/videofile.mp4';
$fp = @fopen($file, 'rb');
$size = filesize($file); // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
header('Content-type: video/mp4');
header("Accept-Ranges: 0-$length");
if (isset($_SERVER['HTTP_RANGE'])) …Run Code Online (Sandbox Code Playgroud) 我在javascript和php中实现视频有问题.
的index.php
session_start()
// do other stuff
include ‘video.php’
Run Code Online (Sandbox Code Playgroud)
video.php
<?php
If(!$_REQUEST[‘play’]){
// displaying video.html
}
else
{
// play video
$fp = @fopen($file, 'rb');
$size = filesize($file); // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
// Now that we've gotten so far without errors we send the accept range header
/* At the moment we only support single ranges.
* Multiple ranges requires some …Run Code Online (Sandbox Code Playgroud) 我正在测试支持HTTP字节范围请求的HTTP servlet实现(由BalusC共享).
我发现不同的HTTP客户端之间存在一些特殊的差异,并且想知道我是否遗漏了任何东西.我使用了> 2G mp4视频文件进行测试,并使用Wireshark捕获数据包.这大致是发生的事情:
三星Galaxy SII:
[0; <almost the end of the file>]每个后续块在同一HTTP响应的范围内提供.没有发送新的HTTP请求(除非视频被快速转发到某个位置).该流码块是相当简单,它读取RandomAccessFile input和写入OutputStream output通过byte[] buffer:
while ((read = input.read(buffer)) > 0) {
output.write(buffer, 0, read);
}
Run Code Online (Sandbox Code Playgroud)[0; <almost the end of the file>]GET请求.例如,新的范围边界[100, almost the end of the file].视频显示正常.我没有调查连接的确切方式.可能是iPad停止发送TCP ACK数据包,我想这并不重要.
我的问题是,对于每个终止的连接,我都会遇到java.net.SocketException: Broken pipe异常.这不仅会污染日志(这是一个小问题/可解决的问题),但我相信这会影响性能,因为提高异常是非常昂贵的.在观看简单视频时,异常率约为1个异常/秒,但如果服务器有100个并发用户,则JVM可能会花费大量时间来计算堆栈跟踪而不是实际工作.
我也使用iOS 6在iPhone上进行了测试,并且能够观察到与iPad 1相同的行为.重申一下,这 …