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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

MP3 files in single audio player (xml/ playlist)


Go to End
Reply


14 Posts   4165 Views

Avatar
CHD

Community Member, 218 Posts

11 September 2010 at 1:01am

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

Avatar
UncleCheese

Forum Moderator, 4096 Posts

11 September 2010 at 1:40am

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

Avatar
CHD

Community Member, 218 Posts

11 September 2010 at 1:42am

cheers UC!
this looks like enough to get me started :D

Avatar
CHD

Community Member, 218 Posts

11 September 2010 at 2:32am

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>

Avatar
CHD

Community Member, 218 Posts

11 September 2010 at 2:32am

am i in ANY way on the right lines?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

11 September 2010 at 2:57am

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'
);

Avatar
CHD

Community Member, 218 Posts

11 September 2010 at 3:01am

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?

Avatar
CHD

Community Member, 218 Posts

11 September 2010 at 3:05am

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?

Go to Top