Community Documentation

Adding an embedded player for audio in 5.0

Last updated August 23, 2009. Created by gbear on February 28, 2007.
Edited by SLIU. Log in to edit this page.

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

About this page

Drupal version
Drupal 5.x

Theming Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here