Это несколько связано с моим другим потоковым потоком в формате PHP, но на этот раз проблема заключается в том, что в Chrome не работает поисковая панель для видео.PHP Video Stream Seekbar недоступен в Chrome
Я нашел несколько разных сообщений об этом здесь, в Stack Overflow, но ни один из них не разрешил проблему. Я бы связал их всех, но я не могу найти те же сообщения, что и вчера.
Я собираюсь перечислить две версии кода PHP. Я также должен указать, что именно я делаю, прежде чем PHP загрузит видеоданные. На HTML-странице у меня есть тег <video>
без тегов <source>
. Я использую Javascript для вызова AJAX в PHP-файл с исходными тегами. Сами исходные теги не содержат прямых ссылок на файлы исходного видео. Вместо этого они ссылаются на еще один файл PHP, который загружает данные.
HTML верхнего уровня для видео. Супер простой.
<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);
?>
Version 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.