Click here to Skip to main content
15,919,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have code to play video in 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();
}

   ?>


problem is that it works fine in pc browser, but after playing it in mobile browser it gets hanged when size of video is large for small video it works fine in mobile browser.

What could be the problem
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