Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » MP3 files in single audio player (xml/ playlist)

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 3948 Views
  • CHD
    Avatar
    Community Member
    218 Posts

    MP3 files in single audio player (xml/ playlist) Link to this post

    So i've got audio files playing fine on my site (http://www.silentrepublic.com/mp3/) but i want to install a single player now with the ability of adding a playlist. but im a bit rubbish with the real technical side of this stuff!

    here's what i have so far (thanks to Uncle Cheese)

    AudioFile.php

    <?php
    class AudioFile extends DataObject {

    static $db = array (
    'AudioTitle' => 'Text',
    'Description' => 'Text'
    );

    static $has_one = array (
    'AudioPage' => 'AudioPage',
    'File' => 'MP3'
    );

    public function getCMSFields() {
    $f = new FieldSet (
    new Textfield('AudioTitle'),
    new TextareaField('Description'),
    $u = new FileUploadField('File')
    );
    $u->setFileTypes(array('mp3'));
    return $f;
    }
    }

    AudioPage.php

    <?php
    class AudioPage extends Page {

    static $has_many = array (
    'AudioFiles' => 'AudioFile'
    );

    public function getCMSFields() {
    $f = parent::getCMSFields();
    $f->addFieldToTab("Root.Content.Audio", new FileDataObjectManager($this));
    return $f;
    }
    }
    class AudioPage_Controller extends Page_Controller {}

    mp3.php

    <?php

    class MP3 extends File
    {
       static $allowed_file_types = array (
          'mp3'
       );

       private static $player_count = 0;
          
       public function Player()
       {
          self::$player_count++;
          return $this->customise(array(
             'SWFLink' => Director::absoluteURL('dataobject_manager/code/mp3/player.swf'),
             'MP3Link' => Director::absoluteURL($this->URL),
             'Count' => self::$player_count
          ))->renderWith(array('mp3'));
       }
       
       public function forTemplate()
       {
          return $this->Player();
       }
       
       
    }

    ?>

    mp3.ss

    <% require javascript(dataobject_manager/code/mp3/audio-player.js) %>

    <object type="application/x-shockwave-flash" data="$SWFLink" id="audioplayer1" height="24" width="290">
       <param name="movie" value="$SWFLink">
       <param name="FlashVars" value="playerID={$Count}&amp;soundFile={$MP3Link}">
       <param name="quality" value="high">
       <param name="menu" value="false">
       <param name="wmode" value="transparent">
    </object>

    AudioPage.ss

    <div id="ColumnLeft" class="typography">
       <h2>$Title</h2>
             $Content

    <% control AudioFiles %>
    <p>$AudioTitle</p>
    <p>$Description</p>
    $File.Player
    <% end_control %>
    </div>

    now can anybody please hep me turn this into a playlisted audio player somehow?
    i imagine it will need to be turned into an xml somehow? i think i can figure out how to change the mp3 file location to an xml location, but then how do i auto generate the xml feed using dataobjectmanager on uploads??

    hope this makes sense!

    thanks so much for any help in advance

  • UncleCheese
    Avatar
    4085 Posts

    Re: MP3 files in single audio player (xml/ playlist) Link to this post

    You need to do three things:

    Create an action on your controller (e.g. "xml()") that sets up an XML response

    Create a template for that action (e.g. YourPage_xml.ss) that builds the XML in normal SS templating practices

    Set your Flash component to point to: yoursite.com/your-page/xml

    You can look at the SlideshowPro module for an example of this. It does something similar to feed a Flash component XML data. You can check that out from SVN here: http://carlinowebdesign.svn.beanstalkapp.com/modules/trunk/slideshow_pro

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: MP3 files in single audio player (xml/ playlist) Link to this post

    cheers UC!
    this looks like enough to get me started

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: MP3 files in single audio player (xml/ playlist) Link to this post

    OK...attempt number 1. (please dont laugh, although it is fairly amusing thati think this would work!)

    here's what ive done.

    mp3.ss

    <% require javascript(dataobject_manager/code/mp3/audio-player.js) %>

    <object type="application/x-shockwave-flash" data="$SWFLink" id="audioplayer1" height="24" width="290">
       <param name="movie" value="$SWFLink">
       <param name="FlashVars" value="soundFile={$MP3Link}">
       <param name="quality" value="high">
       <param name="menu" value="false">
       <param name="wmode" value="transparent">
    </object>

    AudioFile.php

    <?php
    class AudioFile extends DataObject {

    static $db = array (
    'AudioTitle' => 'Text',
    'Description' => 'Text'
    );

    static $has_one = array (
    'AudioPage' => 'AudioPage',
    'File' => 'MP3'
    );

    public function getCMSFields() {
    $f = new FieldSet (
    new Textfield('AudioTitle'),
    new TextareaField('Description'),
    $u = new FileUploadField('File')
    );
    $u->setFileTypes(array('mp3'));
    return $f;
    }
    }

    mp3.php

    <?php

    class MP3 extends File
    {
       static $allowed_file_types = array (
          'mp3'
       );

       private static $player_count = 0;
          
       public function Player()
       {
          self::$player_count++;
          return $this->customise(array(
             'SWFLink' => Director::absoluteURL('dataobject_manager/code/mp3/player.swf'),
             'MP3Link' => Director::absoluteURL($this->Link('xml')),
             'Count' => self::$player_count
          ))->renderWith(array('mp3'));
       }
       
       public function forTemplate()
       {
          return $this->Player();
       }
       
       
    }

    ?>

    AudioPage.php

    <?php
    class AudioPage extends Page {

    static $has_many = array (
    'AudioFiles' => 'AudioFile'
    );

    public function getCMSFields() {
    $f = parent::getCMSFields();
    $f->addFieldToTab("Root.Content.Audio", new FileDataObjectManager($this));
    return $f;
    }
    }
    class AudioPage_Controller extends Page_Controller {
       
          public function xml() {
          header("Content-type: text/xml");
          die($this->renderWith(array('Audio_xml')));
       }
       }

    Audio_xml.ss

    <?xml version="1.0" encoding="UTF-8"?>
    <playlist>
       <% control AudioFiles %>
       <file path="$MP3Link" AudioTitle="$AudioTitle.EscapeXML" Description="$Description.EscapeXML" >
       <% end_control %>   

    </playlist>

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: MP3 files in single audio player (xml/ playlist) Link to this post

    am i in ANY way on the right lines?

  • UncleCheese
    Avatar
    4085 Posts

    Re: MP3 files in single audio player (xml/ playlist) Link to this post

    That looks great! I would change this:

    public function xml() {
    header("Content-type: text/xml");
    die($this->renderWith(array('Audio_xml')));
    }

    to this;

    public function xml() {
    header("Content-type: text/xml");
    return $this->renderWith('Audio_xml');
    }

    Just a little cleaner than die().. I don't know why I did that.

    Go to /your-page/xml and make sure you're getting XML!

    Also, add to your controller

    static $allowed_actions = array (
    'xml'
    );

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: MP3 files in single audio player (xml/ playlist) Link to this post

    wow really??
    cool!!!

    thanks for your quick response trying that now.
    at teh moment when i look for the xml i get this error:

    XML Parsing Error: mismatched tag. Expected: </file>.
    Location: http://www.silentrepublic.com/listen/xml
    Line Number 17, Column 3:</playlist>
    --^

    thats from the URL: http://www.silentrepublic.com/listen/xml
    is that where i should be looking?

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: MP3 files in single audio player (xml/ playlist) Link to this post

    OK i read the error and fixed the issue...

    now i get:

    <playlist>
    <file path="" AudioTitle="Title" Description="The-Motions"/>
    <file path="" AudioTitle="" Description="Emerald City"/>
    <file path="" AudioTitle="" Description="Seek the light"/>
    <file path="" AudioTitle="" Description="Semi Automatic"/>
    <file path="" AudioTitle="" Description="Tomahawk"/>
    <file path="" AudioTitle="" Description="Black-Magic"/>
    </playlist>

    so only descriptions are being imported?

    3948 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.