Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

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

MP3 files in single audio player (xml/ playlist)


Reply

1311 Views

Avatar
CHD

11 September 2010 at 1:01am Community Member, 218 Posts

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 :)