Click here to Skip to main content
15,125,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i had code below to play video through php

PHP
<?php

        /*$file = "d.mp4";
        $file_size = filesize($file);
        $fp = fopen($file, "rb");
        $data = fread ($fp, $file_size);
        fclose($fp);
        header ("Content-type: video/mp4");
        echo $data; */

 $path = 'f.mp4';
 if (file_exists($path))
 {
 $size=filesize($path);
 $fm=@fopen($path,'rb');
 $begin=0;
 $end=$size;
 if(isset($_SERVER['HTTP_RANGE'])) {
    if(preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i',
        $_SERVER['HTTP_RANGE'],$matches)){
        $begin=intval($matches[0]);
        if(!empty($matches[1])) {
            $end=intval($matches[1]);
        }
    }
 }
 if($begin>0||$end<$size)
     header('HTTP/1.0 206 Partial Content');
 else
     header('HTTP/1.0 200 OK');
     header("Content-Type: video/mp4");
     header('Accept-Ranges: bytes');
     header('Content-Length:'.($end-$begin));
     header("Content-Disposition: inline;");
     header("Content-Range: bytes $begin-$end/$size");
     header("Content-Transfer-Encoding: binary\n");
     header('Connection: close');
     $cur=$begin;
     fseek($fm,$begin,0);
     while(!feof($fm)&&$cur<$end&&(connection_status()==0))
         {
        print fread($fm,min(1024*16,$end-$cur));
        $cur+=1024*16;
        usleep(1000);
     }
     die();
 }

    ?>



but problem is that it takes few seconds to start vidoe, and user keeps on clicking play button.

What is want is something like loading should be there so that user may understand that vidoe is loading like you tube.

Please help.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900