•  0
    PHP

    PHP function to stream video in HTML5

      Admin     2222        0        Report content

    In html file, use the video tags

    
    

    Your browser does not support the video tag.

    and in php file, use the following function

    
     $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($stream, $start);
            header('HTTP/1.1 206 Partial Content');
            header("Content-Length: ".$length);
            header("Content-Range: bytes $start-$end/".$size);
            //stream
    	    $i = $start;
    	    set_time_limit(0);
    	    while(!feof($stream) && $i <= $end && connection_aborted() == 0) {
    	        $bytesToRead = $buffer;
    	        if(($i+$bytesToRead) > $end) {
    	            $bytesToRead = $end - $i + 1;
    	        }
    	        $data = fread($stream, $bytesToRead);
    	        echo $data;
    	        flush();
    	        $i += $bytesToRead;
    	    }
        }
        else
        {
            header("Content-Length: ".$size);
            readfile($path);
        }
        //end stream
        fclose($stream);
        exit;
    }
    ?>
    

     


  •  


Leave a Comment

Please Login to insert comment.

 

Facebook Conversations