- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做一个向用户显示视频广告的项目,60 秒后用户可以看到一个链接。我的老板想确保用户观看全部 60 秒。现在我想知道有什么方法可以检查 php 已经看到了多少视频流?为了将视频呈现为流,我使用了以下代码:
http://codesamplez.com/programming/php-html5-video-streaming-tutorial
class VideoStream
{
private $path = "";
private $stream = "";
private $buffer = 102400;
private $start = -1;
private $end = -1;
private $size = 0;
function __construct($filePath)
{
$this->path = $filePath;
}
/**
* Open stream
*/
private function open()
{
if (!($this->stream = fopen($this->path, 'rb'))) {
die('Could not open stream for reading');
}
}
/**
* Set proper header to serve the video content
*/
private function setHeader()
{
ob_get_clean();
header("Content-Type: video/mp4");
header("Cache-Control: max-age=2592000, public");
header("Expires: ".gmdate('D, d M Y H:i:s', time()+2592000) . ' GMT');
header("Last-Modified: ".gmdate('D, d M Y H:i:s', @filemtime($this->path)) . ' GMT' );
$this->start = 0;
$this->size = filesize($this->path);
$this->end = $this->size - 1;
header("Accept-Ranges: 0-".$this->end);
if (isset($_SERVER['HTTP_RANGE'])) {
$c_start = $this->start;
$c_end = $this->end;
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
if (strpos($range, ',') !== false) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $this->start-$this->end/$this->size");
exit;
}
if ($range == '-') {
$c_start = $this->size - substr($range, 1);
}else{
$range = explode('-', $range);
$c_start = $range[0];
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $c_end;
}
$c_end = ($c_end > $this->end) ? $this->end : $c_end;
if ($c_start > $c_end || $c_start > $this->size - 1 || $c_end >= $this->size) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $this->start-$this->end/$this->size");
exit;
}
$this->start = $c_start;
$this->end = $c_end;
$length = $this->end - $this->start + 1;
fseek($this->stream, $this->start);
header('HTTP/1.1 206 Partial Content');
header("Content-Length: ".$length);
header("Content-Range: bytes $this->start-$this->end/".$this->size);
}
else
{
header("Content-Length: ".$this->size);
}
}
/**
* close curretly opened stream
*/
private function end()
{
fclose($this->stream);
exit;
}
/**
* perform the streaming of calculated range
*/
private function stream()
{
$i = $this->start;
set_time_limit(0);
while(!feof($this->stream) && $i <= $this->end) {
$bytesToRead = $this->buffer;
if(($i+$bytesToRead) > $this->end) {
$bytesToRead = $this->end - $i + 1;
}
$data = fread($this->stream, $bytesToRead);
echo $data;
flush();
$i += $bytesToRead;
}
}
/**
* Start streaming video content
*/
function start()
{
$this->open();
$this->setHeader();
$this->stream();
$this->end();
}
}
$stream = new VideoStream($filePath);
$stream->start();
谢谢。
最佳答案
服务器工作在视频下载后立即完成。这必须在客户端完成。您需要一段 javascript,它会在播放视频后显示链接。
关于php - 如何检查用户使用 php 观看了多少视频流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30148952/
我有一个不断增长的日志文件。我如何通过 Ruby 脚本查看和解析它? 脚本将解析写入文件的每个新行,并在新行包含字符串 'ERROR' 时将内容输出到屏幕 最佳答案 def watch_for(fil
我想尝试更新 modelValue 并更改日期选择器中的值 watch(range, (range) => { emit("update:modelValue", range); consol
谁能给我一个例子,说明如何在 ng-include 上观察发射事件?准确地说,我想在我的指令中观察 $includeContentLoaded 事件......这是我的 html:
经过一番努力,我能够使用谷歌驱动器对自己进行身份验证,获取文件列表,获取我想要的文件。现在希望能够捕获google文档数据中的变化,从而知道发生变化的行数和列数。 感觉我的答案就在这里https://
我构建了一个具有指向 promise 的属性的指令。当 promise 解决时,我想运行一个对数据执行某些操作的函数。像这样: scope.$watch('source', function (da
我正在尝试编写一个执行以下操作的 gulp 文件: 运行监视任务,在任何模板更改时重建 Handlebars 模板。 如果构建失败,它会通过notify()方法通知BrowserSync,这样如果出现
我有一个用例,我每天在不同的时刻都有新文件,比如每隔一小时或两小时,所以我需要查看文件夹中的目录,并在添加新文件时触发发送这些新文件的事件我在 NIFI 上的网络服务的路径,知道如何实现这个以及为此使
有人可以推荐一个 JAVA 开源库来监控 FTP 位置更改吗?我正在尝试监视 FTP 位置的更改,一旦检测到更改,更改的文件将被复制到 SVN 位置以进行提交。 最佳答案 Java 远程目录轮询器 (
我想知道是否可以在 Apple Watch Simulator 中模拟心跳,如果可以,如何实现。 谢谢! 最佳答案 是的,您需要使用 HKWorkoutSession 关于xcode - 观看 OS
我目前正在使用 google calendar api 并尝试在 javascript 中编写一个函数,该函数使用 calendar.events.watch 函数以便在用户日历中有更新时进行更新 (
我需要监视网络应用程序中两个目录中的更改(上传的文件)。我创建了一个ServletContextListener来触发对这两个目录的监控。 我的问题是,当第一次监控开始时,线程被阻塞,第二次监控没有启
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improv
我正在开发一个应用程序,当 watch 被激活时,我需要启动一个计时器(使用 NSTimer)。使用计时器,我向 iPhone 询问一些信息(大约每 1 秒一次,最多 5 秒一次)。我用它来启动计时器
我只想向我的 WKInterfaceController 添加图像,但是... Xcode 告诉我: Unable to find image named "circle44" on Watch @I
除了 root_path 之外的所有路由都在产品中中断,即使我的 assert_select 测试所有 GREEN。 The core of the problem was misconfigured
我试图观察用户何时在 IScroll (v5) 中滚动。 我对 angular 还是很陌生,只是在学习编写指令。 从其他示例中,我正在尝试。 我的指令是 app.directive('watchScr
我有一个带有 Controller 的选择输入,当选择一个值时,希望将该值传递给将显示它的指令。 (在本例中,在传单 map 上绘制一个形状)。 问题是我希望该值是“即发即忘” - 因此他们选择形状,
我正在使用 Gulp 来编译和缩小我的 SASS。这工作正常,但我想通过使用 BrowserSync 来扩展自动化。 我已按照一些教程网站上的说明进行操作,但无法使其正常工作 - 当我更新 .scss
一段时间以来,我一直在尝试远离 FTP。 在掌握了 GIT 之后(我错过了什么!),将提交推送到 GitHub,然后最终将更改 pull 到我的远程服务器上并 pull 任何更改)。 我一直在看的一个
我有一个使用 Parse.com 的现有 iOS 应用程序。您可以使用用户名和密码、Facebook 或 twitter 登录,也可以创建新的登录名。我正在准备更新,它有一个 WatchKit 扩展,
我是一名优秀的程序员,十分优秀!