- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在使用 javascript 和 PHP 执行视频时遇到问题。
索引.php
session_start()
// do other stuff
include ‘video.php’
视频.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 more work to ensure it works correctly
* and comply with the specifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
*
* Multirange support announces itself with:
* header('Accept-Ranges: bytes');
*
* Multirange content must be sent with multipart/byteranges media type,
* (mediatype = mimetype)
* as well as a boundary header to indicate the various chunks of data.
*/
header('Content-type: video/mp4');
header('Accept-Ranges: bytes');
// multipart/byteranges
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
if (isset($_SERVER['HTTP_RANGE'])){
$c_start = $start;
$c_end = $end;
// Extract the range string
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
// Make sure the client hasn't sent us a multibyte range
if (strpos($range, ',') !== false){
// (?) Shoud this be issued here, or should the first
// range be used? Or should the header be ignored and
// we output the whole content?
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $start-$end/$size");
// (?) Echo some info to the client?
exit;
} // fim do if
// If the range starts with an '-' we start from the beginning
// If not, we forward the file pointer
// And make sure to get the end byte if spesified
if ($range{0} == '-'){
// The n-number of the last bytes is requested
$c_start = $size - substr($range, 1);
} else {
$range = explode('-', $range);
$c_start = $range[0];
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
} // fim do if
/* Check the range and make sure it's treated according to the specs.
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
*/
// End bytes can not be larger than $end.
$c_end = ($c_end > $end) ? $end : $c_end;
// Validate the requested range and return an error if it's not correct.
if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size){
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $start-$end/$size");
// (?) Echo some info to the client?
exit;
} // fim do if
$start = $c_start;
$end = $c_end;
$length = $end - $start + 1; // Calculate new content length
fseek($fp, $start);
header('HTTP/1.1 206 Partial Content');
} // fim do if
// Notify the client the byte range we'll be outputting
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: $length");
// Start buffered download
$buffer = 1024 * 8;
while(!feof($fp) && ($p = ftell($fp)) <= $end){
if ($p + $buffer > $end){
// In case we're only outputtin a chunk, make sure we don't
// read past the length
$buffer = $end - $p + 1;
} // fim do if
set_time_limit(0); // Reset time limit for big files
echo fread($fp, $buffer);
flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit.
} // fim do while
fclose($fp);
exit();
}
视频.html
<!doctype html>
<html lang="fr-FR">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<video controls>
<source src="index.php?format=mp4&play=1&id=someid type="video/mp4" />
</video>
</body>
</html>
一切正常,但出于某种我不知道的原因,当我开始播放视频然后单击页面上的链接或使用浏览器的后退按钮时,浏览器会卡住并等待一段时间(可变),然后再继续链接。
探查器指示请求的页面更改处于挂起状态。
如果我将视频光标放在更远的地方,浏览器会立即解锁并跟随我点击的链接。
最后,如果我重新加载该页面,问题就不会再出现了。 chrome 似乎在等待某些东西,但由于我的缓存被禁用,它没有被缓存。
这只发生在 chrome 桌面上,所有其他浏览器都可以正常工作。
** 编辑 **
我找到了问题的根源。
为了播放我的视频,我浏览了我的主文件 index.php
,它用作我的路由器,我在其中使用 session_start()
初始化 session 。
当视频正在播放并且我点击链接或浏览器的后退按钮时,我返回到 index.php
。这是 chrome 在 session_start() 期间卡住的时候
只要视频还在播放,好像session有冲突。
最佳答案
如果您没有在 session 中编写任何内容,则在 session_start()
之后使用 session_write_close()
,或者如果您在之后编写一些 session 变量......
当我们启动 session 时,它会打开 session 文件进行读取。读取仅在脚本结束后关闭。同时,如果您要打开新页面,它将卡住。因此请使用此功能来防止它。
https://www.php.net/manual/en/function.session-write-close.php
session_start();
session_write_close();
// do other stuff
include ‘video.php’
您可以在 session_write_close() 之后读取 session 变量..这没有问题..但是如果您在它之后写一些东西..它不会将该值写入 session 变量。
关于php - Chrome 问题 - 视频流和 session 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52823297/
我正在用 symfony2 编写应用程序,但我遇到了视频流问题。 如果一个 Action 需要很长时间才能执行 - 例如 1 分钟,整个应用程序将被卡住(当在第二个选项卡中打开时)并且必须等待该执行结
我正在用 symfony2 编写应用程序,但我遇到了视频流问题。 如果一个 Action 需要很长时间才能执行 - 例如 1 分钟,整个应用程序将被卡住(当在第二个选项卡中打开时)并且必须等待该执行结
我正在尝试用视频流做一个应用程序,现在我只能从服务器向客户端发送一张图像。当我尝试在客户端发送不止一张图像时,我收到以下错误:“参数无效。”在 pictureBox1.Image = new Bitm
我正在使用 mediaViews 和 html5 在我们的 cakephp 网站上流式传输视频截屏。我正在为播放器使用 videojs,但遇到了一些问题: 不会在 safari/ipad/iphone
我已经安装了fluent-ffmpeg和ffmpeg-static以将流转换为HTML可复制的视频。如何使用这些软件包在客户端中显示流? 服务器端( main.js ): const { app, B
我在我的应用程序中实现了 TTS(文本转语音)功能。一切都很顺利,但现在我遇到了一个无法找到解决方案的问题。 基本上,我在激活 TTS 功能之前获得音频焦点。在实际的应用程序中,当我这样做时音乐就会停
我已经执行了开源社区链接发布的 AudioPlayer.java 示例 Audio Player Tutorial 我得到以下异常 Exception in thread "main" java.la
有什么方法可以在iOS原生App中通过URL播放无法下载或保存到本地的视频流。我想让用户观看视频,但他不能在本地下载或保存视频(通过第 3 方下载器应用程序)。 在 MPMoviePlayerCont
我正在开发用于网络吞吐量测试的点对点视频流。两个对等点之间的网络支持低比特率传输。 我使用 OpenCV 为视频流制作了简单的 python 程序。 该程序从网络摄像头抓取视频帧并将其编码为 JPEG
我正在我的应用程序中流式传输实时视频。我有一个 .m3u8 链接,它在 vlc 播放器中完美运行。但是当我在我的应用程序中播放这个流时,视频的可视化被破坏了(见截图)。有谁知道,这可能是什么原因造成的
好的。因此,有数十亿种不同的 Android 设备。我有一个视频流服务,非常适用于 iOS。我的应用程序具有实时视频功能和保存的视频剪辑播放功能(也可以流式传输到设备)。我在不同的 Android 设
我有一个屏幕共享应用程序 (WebRTC)。一个用户想与另一个用户共享他的屏幕。就像一个应用程序在用户 1 机器上运行而另一个应用程序在用户 2 机器上运行。用户 1 想要共享他的屏幕,现在如何在用户
我正在尝试提供即时转码的视频。不幸的是,这意味着寻求不起作用。我假设这是因为浏览器不知道视频有多长,因此无法正确显示搜索栏。 有谁知道是否可以对视频的时长进行硬编码? 我想到的另一个选择可能是创建我自
在将解复用的 h264 解码输出发送到 gstreamer 管道中的 autovideosink 之前,是否可以在两者之间提供一些延迟。如果是这样,任何人都可以发布示例管道来做到这一点。 我使用的管道
一直在把我的头发拉出来,这本来应该是一项快速而简单的任务。 我有一个自托管的 WCF 服务,我需要在其中实现实时视频转码,转码本身不是问题,使用 FFMpeg 到本地临时文件。 我的代码的快速示例;
我想在 C# 应用程序和浏览器之间建立视频流。 我使用 Websockets 进行通信。 视频源是网络摄像头。 我可以请求单个 PNG 帧,但速度太慢了。 websocket 服务器( Ratchet
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
是否可以在 lync 2010 或 2013 中捕获 lync session 的视频流?我已经在我们的实验室中运行了测试版。 UCMA 为 AudioVideoFlow 提供了钩子(Hook),但似
我有一个 ffmpeg 命令,它接收帧流并输出 ogg 视频。如何从另一个文件中添加音频? ffmpeg -f rawvideo -pix_fmt bgr24 -s WIDTHxHEIGHT -r 3
我正在使用全息镜头,并且我正在尝试保存具有可用世界/投影矩阵的视频流。我一直在尝试拍摄一系列照片并保存数据,但我找不到保存图像和矩阵的方法。 保存到磁盘时,没有获取照片捕获帧(包含矩阵数据)的选项,保
我是一名优秀的程序员,十分优秀!