Results 1 to 4 of 4
  1. #1

    Default Streaming/Playing videos in PHP..help.


    hey guys...i want to stream/play a video that is found in my pc to my website using php but when i use the path "C:\upload\video\sample.flv" it does not play the video but when i tried to copy the sample video to my htdocs folder and use "http:\\localhost\sitename\sample.flv" it played the video...
    ive used a premade php class in which i found on the net and along with it are the swf player and swfobject.js.
    here is the class that i used:
    PHP Code:
    <?php
       
      
    class VideoPlayer {
        
          private 
    $errors = array(
          
    => 'No archive joined.',
          
    => 'Invalid extension.',
          
    => 'File error.',
          
    => 'The file does not exist.'
        
    );
        
    /**
         * Error ocurred
         * @var int
         */
        
    private $error 0;
        
    /**
         * url of the video
         * @var String
         */
        
    private $video NULL;
        
    /**
         * Extension of the video
         * @var String
         */
        
    private $extension NULL;
        
    /**
         * Accepted extensions for play
         * @var mixed
         */
        
    private $accepted_extensions = array('wmv''asx','flv','mov','rmv','rmvb','swf''mpg''mpeg');
        
    /**
         * Correct player
         * @var String
         */
        
    private $player =  NULL;
        
    /**
         * Width of the player
         * @var int
         */
        
    private $width 0;
        
    /**
         * Height of the player
         * @var int
         */
        
    private $height 0;
        
    /**
         * If the player is autoplay or no
         * @var String
         */
        
    private $autoplay 'false';
        
    /**
         * If the player show controls or no
         * @var String
         */
        
    private $controls 'false';
        
    /**
         * Javascript for flash flv player
         * @var String
         */
        
    private $swfObject NULL;

        
    /**
         * Class constructor
         *
         * @param String video // Url of the video
         * @param int width // Width of the player
         * @param int height // Height of the player
         * @param String autoplay (true, false) // If the player is autoplay or no
         * @param String constrols (true, false) // If the player show controls or no
         */
        
    public function __construct($video$width$height$autoplay 'false'$controls 'true') {

          
    $this->video    $video;
          
    $this->width    $width;
          
    $this->height   $height;
          
    $this->autoplay $autoplay;
          
    $this->controls $controls;

          if (!
    $this->verifyVideo()) { return false; }

          if(!
    $this->verifyExtension()) { return false; }

        }

        
    /**
         * Verify if archive exists
         *
         */
        
    private function verifyVideo() {

          
    $video = isset( $this->video ) ? $this->video false;

          if( !
    $this->video || $this->video == '' ){
            
    $this->error 1;
            return 
    false;
          } else {
            return 
    true;
          }

        }

        
    /**
         * Verify the video extension
         *
         */
        
    private function verifyExtension() {

          
    $this->extension end(explode('.'$this->video));

          if (!
    in_array($this->extension$this->accepted_extensions)) {
            
    $this->error 2;
            return 
    false;
          } else {
            return 
    true;
          }

        }

        
    /**
         * Return the correct
         *
         */
        
    private function returnPlayer() {

          
    /// Windows media player
          
    if (in_array($this->extension, array('wmv''asx'))) {

            
    $this->player  =
              
    '<object type="video/x-ms-wmv"
              data="'
    .$this->video.'"
              width="'
    .$this->width.'" height="'.$this->height.'">
              <param name="src" value="'
    .$this->video.'" />
              <param name="autostart" value="'
    .$this->autoplay.'" />
              <param name="controller" value="'
    .$this->controls.'" />
              </object>'
    ;

            return 
    true;

          
    /// Real player
          
    } else if (in_array($this->extension, array('rmv''rmvb'))) {

            if (
    $this->controls == 'true') {
              
    $control  'all';
              
    $control_ 'controlpanel';
            } else {
              
    $control  'false';
              
    $control_ 'false';
            }

            
    $this->player  =
              
    '<object id="myMovie" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"
                width="'
    .$this->width.'" height="'.$this->height.'">
              <param name="src" value="'
    .$this->video.'">
              <param name="console" value="video1">
              <param name="controls" value="'
    .$control.'">
              <param name="autostart" value="'
    .$this->autoplay.'">
              <param name="loop" value="false">
              <embed name="myMovie" src="'
    .$this->video.'" width="'.$this->width.'" height="'.$this->height.'"
                autostart="'
    .$this->autoplay.'" loop="false" nojava="false" console="video1" controls="'.$control_.'">
              </embed>
              <noembed><a href="'
    .$this->video.'">Play first clip</a></noembed>
              </object>'
    ;

            return 
    true;

          
    /// Quick time
          
    } else if (in_array($this->extension, array('mov'))) {

            
    $this->player  =
              
    '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
                codebase="http://www.apple.com/qtactivex/qtplugin.cab"
                width="'
    .$this->width.'" height="'.$this->height.'">
              <param name="src" value="'
    .$this->video.'" />
              <param name="controller" value="'
    .$this->controls.'" />
              <param name="autoplay" value="'
    .$this->autoplay.'" />
              <!--[if !IE]>-->
                <object type="video/quicktime"
                  data="'
    .$this->video.'"
                  width="'
    .$this->width.'" height="'.$this->height.'">
                <param name="autoplay" value="'
    .$this->autoplay.'" />
                <param name="controller" value="'
    .$this->controls.'" />
                </object>
              <!--<![endif]-->
              </object>'
    ;

            return 
    true;

          
    /// Mpeg
          
    } else if (in_array($this->extension, array('mpg''mpeg'))) {

            
    $this->player =
            
    '<embed src="'.$this->video.'" autostart='.$this->autoplay.'
              loop=false controller='
    .$this->controls.'
              width="'
    .$this->width.'" height="'.$this->height.'" />';

            return 
    true;

          
    /// Flash video player  
          
    } else if (in_array($this->extension, array('flv'))) {

          
    /*  if ($this->swfObject || $this->swfObject != NULL) {
              $this->player = '<script type="text/javascript" src="'.$this->swfObject.'"></script>';
            } else { */
              
    $this->player =
              
    '<p id="preview">The player will show in this paragraph</p>
              <script type="text/javascript" src="jw_flv_player/swfobject.js"></script>
              <script type="text/javascript">
              var s1 = new SWFObject("jw_flv_player/player.swf","player","400","300","9");
              s1.addParam("allowfullscreen","true");
              s1.addParam("allowscriptaccess","always");
              s1.addParam("flashvars","&file='
    .$this->video.'");
              s1.addVariable("showdigits", "'
    .$this->controls.'");
              s1.addVariable("autostart", "'
    .$this->autoplay.'");
              s1.write("preview");
              </script>'
    ;
                         echo 
    $this->video;
            return 
    true;
            
          
    /// Flash player
          
    } else if (in_array($this->extension, array('swf'))) {

            
    $this->player  =
            
    '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
            codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
             width="'
    .$this->width.'"
             height="'
    .$this->height.'">
            <param name="movie" value="'
    .$this->video.'">
            <param name="wmode" value="transparent">
            <embed src="'
    .$this->video.'"
             wmode="transparent"
             pluginspage="http://www.macromedia.com/go/getflashplayer"
             type="application/x-shockwave-flash"
             width="'
    .$this->width.'"
             height="'
    .$this->height.'">
            </embed>
            </object>'
    ;

            return 
    true;

          
    /// Error
          
    } else {
            
    $this->error 3;
            return 
    false;
          }

        }

        
    /**
         * Return the errors if exist
         *
         * @return String
         */
        
    public function getLastError(){

          if (
    $this->error != 0) {
            return 
    $this->errors[$this->error];
          } else {
            return 
    NULL;
          }

        }

        public function 
    setSwfObject($file) {

          if (
    is_file($file)) {
            
    $this->swfObject $file;
            return 
    true;
          } else {
            
    $this->error 4;
            return 
    false;
          }

        }

        
    /**
         * Return the player
         *
         * @return String
         */
        
    public function player() {

          if(!
    $this->returnPlayer()) { return false; }

          return 
    $this->player;

        }

      }

    ?>
    i hope someone would help me..T__T

  2. #2
    Yep, unless you do have a local server on you pc the stream won't play. Any scripts can only read any files located within any server. It's a protocol otherwise any scripts can "C:\ delete *.*";(delete all) which is scary T_T.

    regards,

  3. #3
    ok rna bro nga naa sa htdocs na folder unless dli ka ganahan.
    pwede rapud maghimo ka ug subfolder nga nagcontain sa imo mga videos.

  4. #4
    yeah...i was hoping nga pde tana...kay dili lng man gud videos ang ako mga files..naa sad mga photos and documents in which ako gi save sa "C:\upload\", gusto tna nko maguban ang mga uploaded files such as photos, documents and videos..hehe..

    but if no other choice gyud..den sa htdocs nlng...hihi..
    tnx sa help guys...

  5.    Advertisement

Similar Threads

 
  1. Error in PHP! Help..
    By cutterpillow20 in forum Programming
    Replies: 9
    Last Post: 10-06-2012, 06:10 PM
  2. help, im stuck! in PHP programming.
    By emailroy2002 in forum Programming
    Replies: 16
    Last Post: 07-08-2010, 11:43 PM
  3. Replies: 12
    Last Post: 10-30-2008, 01:24 PM
  4. DL a photo vs. DL a video in php
    By ichiriki in forum Programming
    Replies: 1
    Last Post: 10-21-2008, 10:24 PM
  5. Replies: 33
    Last Post: 10-17-2008, 04:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top