Adding an embedded player for audio in 5.0
Last modified: August 23, 2009 - 21:11
Noticed in drupal 5, that the correct enclosures for media files are added taking care of podcasts for RSS. By adding an embedded player in a blog, don't need any extra modules for support (like audio module). Need the Upload core module enabled and active for whatever node types will have audio.
Override theme_upload_attachments, checked the mime type for mp3, and then loaded a flash player. Could use any, odeo, XSPF - or in our case used one from google.
The override for template.php
function phptemplate_upload_attachments($files) {
return _phptemplate_callback('upload_attachments', array('files' => $files));
}Created a new template called upload_attachments.tpl.php with the following - embedding the google player.
<?php
$header = array(t('Attachment'), t('Size'));
$rows = array();
foreach ($files as $file) {
if ($file->list) {
$href = $file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()));
$text = $file->description ? $file->description : $file->filename;
if ($file->filemime == "audio/mpeg") { ?>
<p><b>Podcast Audio: <?php print substr($text,0,-4) ?> </b></p>
<object style="border: 1px solid rgb(170, 170, 170); width: 500px; height: 25px;" type="application/x-shockwave-flash"
data="http://mail.google.com/mail/html/audio.swf?audioUrl=<?php print $href; ?>">
<param name="movie" value="http://mail.google.com/mail/html/audio.swf?audioUrl=<?php print $href; ?>" />
</object>
<?php } else {
$rows[] = array(l($text, $href), format_size($file->filesize));
}
}
}
if (count($rows)) {
print theme('table', $header, $rows, array('id' => 'attachments'));
}