Streaming video with PHP Html5 -
i have videos on website, , display them streming php , html5.
i tri follow tutorial (http://codesamplez.com/programming/php-html5-video-streaming-tutorial) of streaming video creation php class.
<?php /** * description of videostream * * @author rana * @link 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 reading'); } } /** * set proper header serve 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 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(); } }
so have 2 problems :
1 - trying stream player video taking on whole page how make video added html5 player.
2 - when make url http video (http://video.newsmed.fr/pdv/0616.mp4) not work
thanks me solve problem or suggest me other solutions php.
- i trying stream player video taking on whole >page how make video added html5 player.
did copy html example without changing thing? @ html5 example, see theres width="100%", can change value fit.
2 - when make url http video (http://video.newsmed.fr/pdv/0616.mp4) >not work
the url should point php code, not video file path. example: yourdomain.com/dir/your-php-file.php?video=0616.mp4
try put your-php-file.php code instead of videostream.php class on question.
Comments
Post a Comment