

The local video plays well with all the browsers. I implemented the video streaming for two videos, one local in the server and one in S3. Then modify the class’s ‘open()’ method, as below: Then, while passing the file path to VideoStream class’s constructor, use “s3://” format as a file string. First, make sure to register ‘streamWrapper’ with your s3 client: $s3Client-> registerStreamWrapper() You can have s3 service’s file location support on the above class very easily. The buffer size is just to optimize the server memory utilization so that no huge memory is taken in case of a concurrent high number of requests. The ‘stream()’ method simply streams the predefined amount of data with a customizable buffer size. Inside ‘setHeader()’ method, it just validates the range requests and decides how much data to send accordingly. When the browser makes a range request, it includes an additional header named ‘HTTP_RANGE’. ‘Accept-Ranges’ header is important to tell the browser that the server is accepting any byte-level request in the given range, so that browser can decide the range itself and make custom range requests subsequently.
HTML5 LIVE STREAM PLAYER MP4
However, at this moment, mp4 is the most widely supported format across major browsers, so using this format is very much recommended. You can change it according to your need. In the header setting, by default mp4 file’s mime type is given.

The header part is the most important as here you will be communicating with the client browser, telling it that you can accept range requests and check if the browser made range requests or not and decide the amount of data to the stream.

It can either give it a local path, or even an amazon s3 file location as well(explained later).Īfter calling the ‘start()’ method, it first tries to open the file, then sets the proper headers, then streams the required contents and finally closes the file system handler. The class simply takes the path of the video file as a constructor parameter.
HTML5 LIVE STREAM PLAYER CODE
Code language: PHP ( php ) Understanding the class and HTML5 Streaming logic:
