- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这与我的其他 PHP 视频流帖子有些相关,但这次的问题是视频的搜索栏在 Chrome 中不起作用。
我在 Stack Overflow 上找到了几篇关于此问题的不同帖子,但没有一个能够解决该问题。我会链接所有这些内容,但我似乎找不到昨天发现的相同帖子。
我将列出 PHP 代码的两个版本。我还应该指出在 PHP 加载视频数据之前我到底在做什么。在 HTML 页面上,我有一个 <video>
标签没有 <source>
标签。我使用 Javascript 对具有源标签的 PHP 文件进行 AJAX 调用。源标签本身不包含视频源文件的直接链接。相反,它们引用另一个加载数据的 PHP 文件。
视频的顶级 HTML。 super 简单。
<video id="showvideo" height="540" width="864" controls></video>
现在进行 AJAX 调用
function showVideo() {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("showvideo").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "/firstphpfile.php", true);
xmlhttp.send();
}
Javascript 函数在页面加载时加载。
这是firstphpfile.php的内容
<?php
echo "
<source src=\"http://example.com/video1.php?type=stuff.mp4\" type=\"video/mp4\">
<source src=\"http://example.com/video2.php?type=stuff.ogv\" type=\"video/ogg\">
";
?>
再说一次,没什么大不了的。现在我将发布几个不同版本的 video1.php 文件,它们实际上获取文件资源。
版本 1:
<?php
$file = video.mp4;
$filesize = filesize($file);
$offset = 0;
$length = $filesize;
if ( isset($_SERVER['HTTP_RANGE']) ) {
// if the HTTP_RANGE header is set we're dealing with partial content
$partialContent = true;
// find the requested range
// this might be too simplistic, apparently the client can request
// multiple ranges, which can become pretty complex, so ignore it for now
preg_match('/bytes=(\d+)-(\d+)?/', $_SERVER['HTTP_RANGE'], $matches);
$offset = intval($matches[1]);
$length = intval($matches[2]) - $offset;
} else {
$partialContent = false;
}
$file = fopen($file, 'r');
// seek to the requested offset, this is 0 if it's not a partial conten request
fseek($file, $offset);
$data = fread($file, $length);
fclose($file);
if ( $partialContent ) {
// output the right headers for partial content
header('HTTP/1.1 206 Partial Content');
header('Content-Range: bytes ' . $offset . '-' . ($offset + $length) . '/' . $filesize);
}
// output the regular HTTP headers
header("Content-Type:video/mp4");
header('Content-Length: $filesize');
header('Accept-Ranges: bytes');
// don't forget to send the data too
print($data);
?>
版本 2(我更喜欢这个版本,因为它在 Firefox 中的功能,但在 Chrome 中仍然没有骰子)
<?php
$file = video.mp4;
$mime = "video/mp4"; // The MIME type of the file, this should be replaced with your own.
$size = filesize($file); // The size of the file
// Send the content type header
header('Content-type: ' . $mime);
// Check if it's a HTTP range request
if(isset($_SERVER['HTTP_RANGE'])){
// Parse the range header to get the byte offset
$ranges = array_map(
'intval', // Parse the parts into integer
explode(
'-', // The range separator
substr($_SERVER['HTTP_RANGE'], 6) // Skip the `bytes=` part of the header
)
);
// If the last range param is empty, it means the EOF (End of File)
if(!$ranges[1]){
$ranges[1] = $size - 1;
}
// Send the appropriate headers
header('HTTP/1.1 206 Partial Content');
header('Accept-Ranges: bytes');
header('Content-Length: ' . ($ranges[1] - $ranges[0])); // The size of the range
// Send the ranges we offered
header(
sprintf(
'Content-Range: bytes %d-%d/%d', // The header format
$ranges[0], // The start range
$ranges[1], // The end range
$size // Total size of the file
)
);
// It's time to output the file
$f = fopen($file, 'rb'); // Open the file in binary mode
$chunkSize = 8192; // The size of each chunk to output
// Seek to the requested start range
fseek($f, $ranges[0]);
// Start outputting the data
while(true){
// Check if we have outputted all the data requested
if(ftell($f) >= $ranges[1]){
break;
}
// Output the data
echo fread($f, $chunkSize);
// Flush the buffer immediately
@ob_flush();
flush();
}
}
else {
// It's not a range request, output the file anyway
header('Content-Length: ' . $size);
// Read the file
@readfile($file);
// and flush the buffer
@ob_flush();
flush();
}
?>
因此,虽然两者都可以毫无问题地播放视频,但只有 Firefox 版本可以让我进行任何类型的搜索。第二个版本使得你只能向后查找,这是我更喜欢的。
我尝试过另一个版本,但在写这篇文章之前我已经删除了代码,并且没有再找到它。
我不确定我做错了什么,而且我发现没有解决方案可以解决允许 Chrome 版本的视频进行搜索的问题。
最佳答案
好的,我终于开始工作了。我决定不使用 javascript 加载 php 文件。
此外,我删除了 mime 类型变量,只正确设置了 header 。我发现使用 mime 类型变量会导致我的浏览器为内容类型 header 加载错误的 mime 类型,从而导致视频资源失败。
关于javascript - PHP 视频流 Seekbar 在 Chrome 中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37282334/
我正在使用 Seek Bar 制作 android 应用程序在这里,我试图为 Android 中的 Seek 栏提供间隔。同样 0 25 50 100(即它应该同样进行 0 25 50 75 100)
我有一个 ListView,它的每一行都有一个 SeekBar。列表的大小和 SeekBar 的数量会有所不同。 我设置了一个 SeekBar.OnSeekBarChangeListener,然后我根
我遇到了一个奇怪的问题。在我的应用程序中,我有一个自定义 SeekBar,它带有一个具有 2 种状态的拇指。当我单击 seekBar 时,它的拇指会变形,并在几秒钟后恢复到正常状态。相应的 Media
我想创建一个Seekbar,上面的每个Seekbar步骤都会有文本标签,它应该如下图所示 这是我所做的预期结果,
我需要实现自定义缩略图 Drawable 吗? 最佳答案 通过深入挖掘,我发现了如何提供自定义 Drawable 缩略图。这是可能对其他人有帮助的摘录。 ShapeDrawable thumb =
我在安卓系统工作。我想在我的应用程序中添加搜索栏的功能。 这是我的 xml 文件:- And this is my java code related to this seek bar. mS
我想让搜索栏拇指完全不可见。但是,下面的代码: seekBar.getThumb().mutate().setAlpha(0); 使缩略图不出现,但缩略图似乎在其搜索栏中形成一个“洞”,如下图所示。
这个问题在这里已经有了答案: Android SeekBar set progress value (10 个答案) 关闭 4 年前。 我在 fragment 中使用 Seekbar,需要将 See
我的布局上有一个高度较小 (3dp) 的 SeekBar(seekBar1)。因为它的高度很小很难选择那个 View ,所以我想实现另一种方法来更新我的搜索 View 的进度。为此,我想这样的事情:我
我有一个包含三个 fragment 的 viewPager。中间(第二个) fragment 在其中实现了一个 seekBar。当我尝试滑动搜索栏时,viewPager 更改了 fragment 。
我有一个带有 TableLayout 的 Android 应用程序,每行都有一个 SeekBar 和一个 ToggleButton。这些行超出了屏幕的可见范围,因此它是可滚动的。当我触摸并拖动以向上滚
我想在我的 Android 应用程序中设置一个 slider ,但要有很好的控制。我有以下代码来定义 bar 及其范围: skBar = new SeekBar (this); skBar.setBa
我想实现如图所示的类似用户界面。我的点均匀分布,但如何在均匀分布的下方添加图像。 enter image description here github.com/woxingxiao/BubbleSe
我正在尝试创建一个搜索栏,用户可以在其中告知 0,000 美元到 10,000 美元 的价格。我已经尝试实现该行: float value = ((float)progress/10.0); 但 an
我想创建我自己的 SeekBar,这意味着我想在绘图上有两个水平 slider 。 我该怎么做?我刚刚设法将一个类绑定(bind)到绘制绘图的 View ,但如何在其上放置两个 slider ?我正在
我正在创建一个简单的应用程序,它在顶部显示一个带有菜单的 GridView 。单击其中一个菜单按钮时,会在其正下方的 View 上放置一个搜索栏。然后用户可以移动 slider 来更改 gridvie
我用过 this link用两个拇指实现SeekBar,我得到了输出。 但是这个搜索栏有一个问题,它允许 thumb 1 和 thumb 2 的交叉,即它允许 thumb 1 的值大于根据我的要求,不
我有一个媒体播放器搜索栏,在我旋转屏幕之前它工作正常。我希望看到的是搜索栏的进度继续。然而它重置为零并且不再响应触摸事件。 这是 oncreate 中的代码: mSeekBar.setOnTouchL
使用 TextView ,我使用此代码更改文本大小。现在我用 textswitcher 改变了 textview,我不能用它来使用“setTextSize”。应该使用哪种方法? mSwitcher =
当屏幕旋转时,我的搜索栏的彩色条会回到其初始值,而拇指仍保持在正确的位置。 基本上是这样的: 变成这样: 请注意,显示 15 的 TextView 连接到搜索栏并正确显示相同的值,该值在 onCrea
我是一名优秀的程序员,十分优秀!