title: Streaming video with PHP Html5
body: <p>I have videos on my website, and I would like to display them streming with Php and html5.</p>
  
  <p>I tri to follow this tutorial 
  (<a href="http://codesamplez.com/programming/php-html5-video-streaming-tutorial" rel="nofollow">http://codesamplez.com/programming/php-html5-video-streaming-tutorial</a>) of streaming video creation with php class.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?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-&gt;path = $filePath;
      }
       
      /**
       * Open stream
       */
      private function open()
      {
          if (!($this-&gt;stream = fopen($this-&gt;path, 'rb'))) {
              die('Could not open stream for reading');
          }
           
      }
       
      /**
       * Set proper header to serve the 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-&gt;path)) . ' GMT' );
          $this-&gt;start = 0;
          $this-&gt;size  = filesize($this-&gt;path);
          $this-&gt;end   = $this-&gt;size - 1;
          header("Accept-Ranges: 0-".$this-&gt;end);
           
          if (isset($_SERVER['HTTP_RANGE'])) {
    
              $c_start = $this-&gt;start;
              $c_end = $this-&gt;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-&gt;start-$this-&gt;end/$this-&gt;size");
                  exit;
              }
              if ($range == '-') {
                  $c_start = $this-&gt;size - substr($range, 1);
              }else{
                  $range = explode('-', $range);
                  $c_start = $range[0];
                   
                  $c_end = (isset($range[1]) &amp;&amp; is_numeric($range[1])) ? $range[1] : $c_end;
              }
              $c_end = ($c_end &gt; $this-&gt;end) ? $this-&gt;end : $c_end;
              if ($c_start &gt; $c_end || $c_start &gt; $this-&gt;size - 1 || $c_end &gt;= $this-&gt;size) {
                  header('HTTP/1.1 416 Requested Range Not Satisfiable');
                  header("Content-Range: bytes $this-&gt;start-$this-&gt;end/$this-&gt;size");
                  exit;
              }
              $this-&gt;start = $c_start;
              $this-&gt;end = $c_end;
              $length = $this-&gt;end - $this-&gt;start + 1;
              fseek($this-&gt;stream, $this-&gt;start);
              header('HTTP/1.1 206 Partial Content');
              header("Content-Length: ".$length);
              header("Content-Range: bytes $this-&gt;start-$this-&gt;end/".$this-&gt;size);
          }
          else
          {
              header("Content-Length: ".$this-&gt;size);
          }  
           
      }
      
      /**
       * close curretly opened stream
       */
      private function end()
      {
          fclose($this-&gt;stream);
          exit;
      }
       
      /**
       * perform the streaming of calculated range
       */
      private function stream()
      {
          $i = $this-&gt;start;
          set_time_limit(0);
          while(!feof($this-&gt;stream) &amp;&amp; $i &lt;= $this-&gt;end) {
              $bytesToRead = $this-&gt;buffer;
              if(($i+$bytesToRead) &gt; $this-&gt;end) {
                  $bytesToRead = $this-&gt;end - $i + 1;
              }
              $data = fread($this-&gt;stream, $bytesToRead);
              echo $data;
              flush();
              $i += $bytesToRead;
          }
      }
       
      /**
       * Start streaming video content
       */
      function start()
      {
          $this-&gt;open();
          $this-&gt;setHeader();
          $this-&gt;stream();
          $this-&gt;end();
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>So i have two problems :</p>
  
  <p>1 -  I am also trying to stream to a player but the video is taking over my whole page how do i make the video is just added to my html5 player.</p>
  
  <p>2 - when I make a url http video (<a href="http://video.newsmed.fr/pdv/0616.mp4" rel="nofollow">http://video.newsmed.fr/pdv/0616.mp4</a>) that does not work</p>
  
  <p>Thanks to help me solve this problem or suggest me other solutions php.</p>