Streaming an mp4 through a php file progressively

后端 未结 5 1551
无人及你
无人及你 2021-02-09 13:45

I\'m working on a more secure streaming method for our video player. Because each file requires special token authentication and also only allows each token to be loaded once, I

5条回答
  •  滥情空心
    2021-02-09 14:17

    Fully Functional Code

    $file = "z.mp4";
    $length= filesize($file);
    $offset = 0;
    $f = fopen($file, 'r');
    stream_get_contents($f, $offset);
    $pos = 0;
    while($pos < $length){
         $chunk = min($length-$pos, 1024*8);
         echo fread($f, $chunk);
         flush();
         ob_flush();
         $pos += $chunk;
    }
    

提交回复
热议问题