I'm trying to feed an mp4 file to flash player via php and the video is downloaded completely before starting playback.
$src = '/var/www/user/data/www/domain.com/video.mp4';
if(file_exists($src) and is_readable($src)) {
header('Content-Type: video/mp4');
header('Content-Length: '.filesize($src));
readfile($src);
} else die('error');
I've tried curl with similar results. Any ideas what's causing this delay?
Most likely your Flash player is hoping you'll handle HTTP
Range
requests so it can get started faster on the playback.The HTML5/Flash audio player jPlayer has a section in their developer guide about this. Scroll to the part about Byte-Range Requests:
Also note that they offer a PHP solution for handling
Range
requests if you have to use PHP instead of a direct download.smartReadFile.php
https://groups.google.com/forum/#!msg/jplayer/nSM2UmnSKKA/bC-l3k0pCPMJ
Another option would be to just have apache send the file it self as opposed to reading it in php and dumping it to the output using X-Sendfile.
First make sure apache is compiled with sendfile support then alter your output code to be:
This is normally faster than doing it via PHP.