VideoJS Flash Version doesn't Play Files (PHP Passthrough Stream) -


i using newest version of videojs , put videos through php in following way:

called like: $this->streaming->handledownload($videopath, "video/mp4");

the function defined like:

public function handledownload($file, $mime = "") {      if (is_file($file)) {         header("content-type: $mime");          if (isset($_server['http_range']))  { // device supports byte-ranges not iphone             header("x-info: starting ranged download of $file");             $this->rangedownload($file);         } else {             header("content-length: ".filesize($file));             header("x-info: starting straight download of $file");             readfile($file);         }     } else {         header("http/1.1 500 internal server error");         $msg = "the requested path no file!";     } } 

the rangedownload() defined:

private function rangedownload($file) {     ob_end_clean();     $fp = @fopen($file, 'rb');      $size   = filesize($file); // file size     $length = $size;           // content length     $start  = 0;               // start byte     $end    = $size - 1;       // end byte      header("accept-ranges: 0-$length");     if (isset($_server['http_range'])) {          $c_start = $start;         $c_end   = $end;         // extract range string         list(, $range) = explode('=', $_server['http_range'], 2);         // make sure client hasn't sent multibyte range         if (strpos($range, ',') !== false) {             header('http/1.1 416 requested range not satisfiable');             header("content-range: bytes $start-$end/$size");             exit;         }         header("x-got-range: $range, $range0");         // if range starts '-' start beginning         // if not, forward file pointer         // , make sure end byte if spesified         if ($range0 == '-') {             $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;         }          // end bytes can not larger $end.         $c_end = ($c_end > $end) ? $end : $c_end;         // validate requested range , return error if it's not correct.         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");             // (?) echo info client?             exit;         }         $start  = $c_start;         $end    = $c_end;         $length = $end - $start + 1; // calculate new content length         fseek($fp, $start);         header('http/1.1 206 partial content');     }      // notify client byte range we'll outputting     header("content-range: bytes $start-$end/$size");     header("content-length: $length");      // start buffered download     $buffer = 1024 * 8;     while(!feof($fp) && ($p = ftell($fp)) <= $end) {          if ($p + $buffer > $end) {              // in case we're outputtin chunk, make sure don't             // read past length             $buffer = $end - $p + 1;         }         set_time_limit(0); // reset time limit big files         echo fread($fp, $buffer);         flush(); // free memory. otherwise large files trigger php's memory limit.     }      fclose($fp); } 

i passing video through php, because files should visible when logged in. things partial content/ranges because want able click in middle of position bar , video should start play there.

that works chrome, newer safari, ios, (because of flash fallback) doesn't work in ie or firefox (video mp4) (perhaps takes long load)

the range works in chrome, well, flash version of videojs doesn't ask range-download, gets other version.

if play video directly (with php-streaming, without videojs) in firefox (just call video-url in url bar) starts directly , loads while plays; videojs doesn't

what need change videos starts play directly in videojs flash-version?

i have found solution (by accident ;-) )

the problem was, flash-player asks video complete file. long server doesn't answer, there streaming-versions available (accept-ranges: 0-$size) player doesn't ask them.

so set header , worked.

so small tutorial have problems videojs flash fallback:

  • videos need encoded via mp4box (see mp4 in video.js not playing until loaded)
  • the php passthrough script needs send following headers:

    header("content-type: $videomimetype"); header("content-length: $videobytecount"); header("accept-ranges: 0-$videobytecount");

  • if want handle range (identified isset($_server["http_range"]) ) need specify headers:

    header("content-range: bytes $startbyte-$endbyte/$videobytecount");

this works me (see code in question). works chrome, ff, ios, safari (ie not tested yet) flash , html5 mp4-files


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -