Jump to:

23355 Posts in 17838 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » display all the video in a uploaded folder in a page

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2364 Views
  • anujkryadav
    Avatar
    Community Member
    30 Posts

    display all the video in a uploaded folder in a page Link to this post

    hello
    i need to show all the video present in a uploaded folder in my home page,Please lete me know how to do that.Video can be in mp4 or avi format
    thank you in advance

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: display all the video in a uploaded folder in a page Link to this post

    I would say either use the YouTube Module (and modify it) and host the files on YouTube or look at the Gallery Module as it pulls images from a specified directory and will show you the setup for adding the correct db and cms fields to your HomePage type. Hope this make sense

  • Rishi
    Avatar
    Community Member
    97 Posts

    Re: display all the video in a uploaded folder in a page Link to this post

    thanks for your reply
    Yes you are correct it does make sense but the problem is when i try to read all the video the video is not getting played as we need specific code to play a video and also we need to change the video format into flv so tht it can be viewed in pages

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: display all the video in a uploaded folder in a page Link to this post

    I believe flash version 9 can use an external .mp4 file this is the standard for vodcasting I have used Jquery Flash Plugin to generate the embed tags and load a flash player I wrote in actionscript basically just loads/plays the movie via flashvars

    $(function(){
    $('#vodcast').flash(
    {
    src: 'website/flash/vodcast_player.swf',
    width: 240,
    height: 205,
    flashvars: { src: 'somefile.mp4' },
           wmode: 'transparent'
    },
    { version: 9 }
    );
    });

    You can see an example here the whole vodcasts are controlled in the backend by silverstripe so this is possible!

  • Rishi
    Avatar
    Community Member
    97 Posts

    Re: display all the video in a uploaded folder in a page Link to this post

    your site looks great ,
    Can you please let me know how to achieve the same in my page,Please let me know in which file i need to write the code and where and how to call it in template,

    thank you in advance

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: display all the video in a uploaded folder in a page Link to this post

    1) Create a flash file that will load and external .mp4 file via flashvars using flash 9.0 AS3 Netstream

    2) Download jquery.flash.js

    4) Create your video page type and a holder page type

    VodcastPage.php

    class VodcastPage extends Page
    {
       static $db = array(
          'Episode' => 'Text',
          'Date' => 'Date',
          'Summary' => 'HTMLText',
          'RunningTime' => 'Time'
          /*'Archive' => 'Boolean'*/
       );
       
       static $has_one = array('MP4'=>'File');
       

       
       function getCMSFields()
       {
          $fields = parent::getCMSFields();
          
          // remove default fields.
          $fields->removeFieldFromTab('Root.Content.Main', 'Title');
          $fields->removeFieldFromTab('Root.Content.Main', 'MenuTitle');
          $fields->removeFieldFromTab('Root.Content.Main', 'Content');
          
          $fields->addFieldToTab('Root.Content.Main', new TextField('Episode'));
          $fields->addFieldToTab('Root.Content.Main', new TextField('Title', 'Title'));
          $fields->addFieldToTab('Root.Content.Main', new TextField('MenuTitle', 'Menu Title'));
          $fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date', 'Date'));
          
          $fields->addFieldToTab('Root.Content.Main', new TextField('RunningTime', 'Running Time (HH:MM:SS)'));
          
          
          $fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('Summary', 'Summary'));
          
          // file upload
          $vodfile = new FileIFrameField('MP4', 'Upload MP4 File (.m4v)', NULL, NULL, NULL, 'vodcasts');

          $fields->addFieldToTab("Root.Content.Main", $vodfile);
             
          return $fields;
    }
       
       function Mp4File()
       {
          $file = DataObject::get('File', "`ID` = '{$this->MP4ID}'");
          if($file) {
             return $file->First();
          }
       }
       
       function Mp4Download()
       {
          $file = self::Mp4File();
          header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the past
          header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
          header("Last-Modified: ".date("D, d M Y H:i:s")." GMT");
          header("Content-type: video/m4v");
          header("Content-Disposition: attachment; filename=".basename(str_replace(' ', '_', $file->getFilename())));
          header("Content-Transfer-Encoding: binary");
          readfile($file->getFullPath());
       }
       
       function getFilename()
       {
          $file = self::Mp4File();
          return $file->Filename;
       }
       
       function getFileURL()
       {
          return self::BaseHref().self::getFilename();
       }
       
       function getFilesize()
       {
          $file = self::Mp4File();
          if($file) {
             return $file->getSize();
          }
       }
       
       function getFilesizeBytes()
       {
          $file = self::Mp4File();
          if($file) {
             return $file->getAbsoluteSize();
          }
       }
    }

    class VodcastPage_Controller extends Page_Controller {
       
       function init()
       {
          parent::init();
          
       }
       
       function download()
       {
          VodcastPage::Mp4Download();
       }
    }
    ?>

    VodcastHolder.php

    class VodcastHolder extends Page
    {

       static $db = array();
       
       static $has_one = array();
       
       static $allowed_children = array('VodcastPage');
       static $default_child = "VodcastPage";
       
    }

    class VodcastHolder_Controller extends Page_Controller {
       
       function init()
       {
          parent::init();
          Requirements::JavaScript('website/javascript/jquery.flash.js');
          // important the src varibale will need to be modified and retrieve the lastest Vodcasts file path you will have top work this out as I had this in the template this was before silverstripe put all scripts at the bottom of page
    Requirements::customScript(<<<JS

    $(function(){
    $('#vodcast-playnow').flash(
    {
    src: 'website/flash/vodcast_player.swf',
    width: 240,
    height: 205,
    flashvars: { src: 'somefile.mp4' },
    wmode: 'transparent'
    },
    { version: 9 }
    );
    });
    JS
    );

       }
       
       
       function iTunesLink()
       {
          return str_replace('http://', 'itpc://', self::AbsoluteLink()) . "rss";
       }
       
       function LatestVodcast()
       {
          $page = DataObject::get_one("VodcastHolder");
           $vodcast = DataObject::get("VodcastPage", "`SiteTree`.ParentID = $page->ID", "Date DESC", NULL, 1);
          if($vodcast) {
             return $vodcast->First();
          }
       }
       
       function LatestMp4()
       {
          $vodcast = self::LatestVodcast();
          $file = DataObject::get("File", sprintf("File.ID = %d", $vodcast->MP4ID));
          if($file) {
             return $file->First();
          }
       }
       
       function LatestMp4Filename()
       {
          $file = self::LatestMp4();
          if($file) {
             return $file->Filename;
          }
       }
       
       function LatestMp4Filesize()
       {
          $file = self::LatestMp4();
          if($file) {
             return $file->getSize();
          }
       }
       
    }

    5) Create template for VodcastHolder

    <% if LatestVodcast %>
    <div id="latestvodcast">
    <div class="inner">
    <% control LatestVodcast %>
    <h3>$Episode $Title.XML</h3>
    <p class="date">$Date.Day, $Date.Long</p>
    $Summary
    </div>
    <div id="vodcast-playnow"></div>
    <div id="vodcast-info">
    <span class="running-time">Running Time: $RunningTime</span>
    &nbsp;&nbsp;&nbsp;<span class="filesize">Size: $Top.LatestMp4Filesize</span>
    <span class="link"><a href="$URLSegment/download">Download full size video</a></span>
    </div>
    </div>
    <% end_control %>
    <% end_if %>

    Sorry I can't explain in more detail but gives you the general idea on how I did it, hope this helps some.

  • anujkryadav
    Avatar
    Community Member
    30 Posts

    Re: display all the video in a uploaded folder in a page Link to this post

    thanks you CodeGuerrilla
    you really saved me a lot of time and you code helped me a lot,thank you once again

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: display all the video in a uploaded folder in a page Link to this post

    No problem glad to help

    2364 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.