7

I am trying to build an application in which i have to stream the media files (audio and video) to the browser. I am reading the file through php and send the data to browser. I am using the following code.

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-Type: {$file->getMimetype()}");
header("Content-Disposition: inline; filename=".$filename.";");
header("Content-Length: ".strlen($file_content));

echo $file_content;

Every thing is working fine, except when i try to forward the video or audio, (I mean suppose current play location is 0:15 and it directly go to 1:25), media stops and when i press the play button again, it starts from the beginning.

I think the problem is with the buffering, but can't figure it out. Am i doing something wrong in header or something else is required.

Thanks.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Chetan Sharma
  • 2,539
  • 5
  • 25
  • 41
  • I prefer Flash-streaming ;) , less filesize = faster loading.. Also easier to integrate into a website. –  Sep 24 '10 at 08:09
  • 3
    @Jordy AFAIK Flash does not do the streaming the server does. You still need a server side script to stream an flv otherwise you would have to wait for the entire file to load before you can view it. – Ultimate Gobblement Sep 24 '10 at 09:18
  • 1
    folow that you can fast forward : __http://codesamplez.com/programming/php-html5-video-streaming-tutorial__ – vuhung3990 Nov 12 '14 at 08:12

4 Answers4

5

I think you need to implement the Range header, so that the client can skip to a specific position in the file. You can probably find out what goes wrong by sniffing the request the player sends.

hakre
  • 193,403
  • 52
  • 435
  • 836
Sjoerd
  • 74,049
  • 16
  • 131
  • 175
  • Is it the players property to send which position to seek, I mean do i have to set te script in the player to specify the seek position and send then to the server. – Chetan Sharma Sep 24 '10 at 10:10
  • the link is dead now. – LF00 Jun 17 '17 at 17:08
  • 1
    But the archive works: https://web.archive.org/web/20111207023157/http://linuxonly.nl/docs/38/122_Introduction.html – hakre Jun 17 '17 at 17:11
4

What you want is called "Content-Range requests"

Have a look here Resumable downloads when using PHP to send the file?

Community
  • 1
  • 1
0

I came across this recently which may help you:

http://www.jasny.net/articles/how-i-php-x-sendfile/

Rather than passing the whole file through PHP (which eats up memory), you can use x-sendfile. This is an Apache module which allows you to run a PHP program, but pass control back to the web server to handle the actual file download once your code has done what it needs to do (authentication, etc).

It means that your PHP code doesn't have to worry about how the file is served; let the web server do what it's designed for.

Hope that helps.

Spudley
  • 166,037
  • 39
  • 233
  • 307
0

Here is a good tutorial for it, you only want the PHP section but still: http://www.devshed.com/c/a/PHP/Video-Streaming-PHP-Script-Tutorial/3/

Olical
  • 39,703
  • 12
  • 54
  • 77