Jump to content

Help needed with streaming a video


BinaryBird

Recommended Posts

Hi, i am trying to stream a video from Rackspace clould files account. I could simply get the url of the video file and stream the video using the php api they have provided. But they have provided a stream function which they suggest to be used for video streaming or for large images.

 

Here is the code of the api :

    /**
         * Streaming read of Object's data
         *
         * Given an open PHP resource (see PHP's fopen() method), fetch the Object's
         * data and write it to the open resource handle.  This is useful for
         * streaming an Object's content to the browser (videos, images) or for
         * fetching content to a local file.
         *
         * Pass in $hdrs array to set specific custom HTTP headers such as
         * If-Match, If-None-Match, If-Modified-Since, Range, etc.
         *
         * Example:
         * <code>
         * # ... authentication/connection/container code excluded
         * # ... see previous examples
         *
         * # Assuming this is a web script to display the README to the
         * # user's browser:
         * #
         * <?php
         * // grab README from storage system
         * //
         * $my_docs = $conn->get_container("documents");
         * $doc = $my_docs->get_object("README");
         *
         * // Hand it back to user's browser with appropriate content-type
         * //
         * header("Content-Type: " . $doc->content_type);
         * $output = fopen("php://output", "w");
         * $doc->stream($output); # stream object content to PHP's output buffer
         * fclose($output);
         * ?>
         *
         * # See read() above for a more simple example.
         * #
         * </code>
         *
         * @param resource $fp open resource for writing data to
         * @param array $hdrs user-defined headers (Range, If-Match, etc.)
         * @return string Object's data
         * @throws InvalidResponseException unexpected response
         */
        function stream(&$fp, $hdrs=array())
        {
            list($status, $reason) =
                    $this->container->cfs_http->get_object_to_stream($this,$fp,$hdrs);
            #if ($status == 401 && $this->_re_auth()) {
            #    return $this->stream($fp, $hdrs);
            #}
            if (($status < 200) || ($status > 299
                    && $status != 412 && $status != 304)) {
                throw new InvalidResponseException("Invalid response (".$status."): "
                    .$reason);
            }
            return True;
        }

 

Here is the sample code they shared :

    $output = fopen("test.jpg", "w");
      $pic->stream($output);
      fclose($output);

 

If i echo the $pic variable, it just contains the name of the file. How do i display the image and how do i use this for streaming a video? Iam very new to php, so kindly help me. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/210670-help-needed-with-streaming-a-video/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.