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.
The PHP wrapper allows access to the languages' own input and output streams, along with access to temporary memory and disk-backed file streams. To get access to the standard input stream, you can use php://stdin, which is read-only.
If the media plays in the Chrome browser, click the Google Cast button and send it to your HDTV. Here's an example of streaming an MP3 file. You can even stream compatible media files from Google Drive. The quality of the stream will depend on the state of your WiFi router and the amount of traffic on the network.
PHP will let you build the pages of your site that make up your video conferencing and chat applications, but it won't deliver or stream video for you - PHP runs on the server only and renders out HTML to a client browser.
The streamWrapper class ¶Allows you to implement your own protocol handlers and streams for use with all the other filesystem functions (such as fopen(), fread() etc.). Note: This is NOT a real class, only a prototype of how a class defining its own protocol should be.
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.
What you want is called "Content-Range requests"
Have a look here Resumable downloads when using PHP to send the file?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With