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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.