I found the code beneath, i can upload now and save but the template is not showing the variable. probably because the "extends File" is not supported for SS3.1.4.
<?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(
'MP3Link' => Director::absoluteURL($this->URL),
'Count' => self::$player_count
))->renderWith(array('mp3'));
}
public function forTemplate()
{
return $this->Player();
}
}
?>
--------------------------------------------------------------------
This is my MusicObject
<?php
class MuziekObject extends DataObject {
static $db = array(
'SortOrder'=>'Int',
'Titel' => 'Varchar',
'Eigenaar' => 'Varchar',
'GenreTag' => 'Varchar',
);
static $has_one = array(
'Attachment' => 'MP3',
'ConnectionToSoundPage' => 'SoundPage',
);
public static $summary_fields = array(
'Titel' => 'Plaatsnaam',
'Eigenaar' => 'Eigenaar'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields-> addFieldToTab('Root.Main', new UploadField('Attachment', 'Muziek bestand'));
$fields->removeFieldFromTab("Root.Main","ConnectionToSoundPageID");
$fields->removeFieldFromTab("Root.Main","SortOrder");
return $fields;
}
function link() {
return $this->Attachment()->Filename;
}
}
----------------------------------------------------------------------------------
In the template file is use this
<% loop MuziekObject %>
<div class="audio-player">
<div class="audio-title"><h2>Gitaarhero</h2><h2>$Titel</h2></div>
<audio id="audio-player" src="assets/Muziek/$Attachment" type="audio/mp3" controls="controls"></audio>
<% loop Attachment %> $MP3Link <% end_loop %>
</div>
<% end_loop %>