Help needed with streaming a video

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BinaryBird
Forum Newbie
Posts: 9
Joined: Tue Dec 22, 2009 1:26 pm

Help needed with streaming a video

Post by BinaryBird »

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 :

Code: Select all

    /**
         * 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 the support team shared :

Code: Select all

    $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.
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: Help needed with streaming a video

Post by buckit »

use YouTube... Upload and then embed to your site :) if you dont want to do that then all i can suggest is to contact RackSpace.

Only way someone can really help you on here is if you manage you catch someones attention that has experience with the API you are referencing.
BinaryBird
Forum Newbie
Posts: 9
Joined: Tue Dec 22, 2009 1:26 pm

Re: Help needed with streaming a video

Post by BinaryBird »

I did contact the support team, and they said the code they provided was the max they will help with coding.
Post Reply