6
Hello! I am using a "player" (in php) to open my external videos.
However the user does not have control of the length bar of the video, he can not have control, nor return the video, nor advance, and it hurts me a lot.
Player php 01
$video = "http://www.blogger.com/video-play.mp4?contentId=b65e1fd886cd357";
header('Content-Type: video/mp4');
readfile ($video);
With player 01, as I said, the user has no control over the duration bar.
I ended up finding another code, where the user gets to have control with some changes.
Player php 02
$request = "video.mp3";
$file = $request;
$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'])) {
$c_start = $start;
$c_end = $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 $start-$end/$size");
exit;
}
if ($range == '-') {
$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;
}
$c_end = ($c_end > $end) ? $end : $c_end;
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");
exit;
}
$start = $c_start;
$end = $c_end;
$length = $end - $start + 1;
fseek($fp, $start);
header('HTTP/1.1 206 Partial Content');
}
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: ".$length);
$buffer = 1024 * 8;
while(!feof($fp) && ($p = ftell($fp)) <= $end) {
if ($p + $buffer > $end) {
$buffer = $end - $p + 1;
}
set_time_limit(0);
echo fread($fp, $buffer);
flush();
}
fclose($fp);
exit();
With player 02, the problem is that it can’t pull from external sites such as blogger.
I need a solution so that Player php 01 can make the duration bar accessible, or a solution so that Player php 02 can pull from external site.
I really need to use the php readfile, I can’t use another player.
A Javascript solution would be easier. Your server communicating with others who don’t have webservice doesn’t seem very secure
– Sveen
@Luanpedro, I don’t know about the rule of your business, but what is the possibility of you downloading the video to the server and making the call locally?
– David Dias
Another thing, I believe that through the
@fopen($file, 'rb');
you may not be able to do these negotiations remotely because it’s not a stream, that is, you don’t keep a connection to anything to get or send something additional, it literally just opens.– David Dias
I cannot use javascript =/ > Sveen It would be impossible, I would have to upload thousands of files to my server > David dias
– Luan pedro