Adding a flash player to the Drupal RSS Remote Enclosure module

Date: Sat Apr 26 2014 Podcasting »»»» Drupal

On 7gen.com I am running a podcast about sane uses of technology and am using the RSS Remote Enclosure module to handle creating the podcast feed. A podcast is merely an RSS feed where the items have enclosure tags referencing audio or video files which are the podcast episodes. Out of the box Drupal creates enclosure tags if you upload a file, but the server on which 7gen.com is hosted doesn't have much disk space. Fortunately my Dreamhost account has oodles of disk space, I'm using it to store the media files, and hosting the podcast on 7gen.com.

The RSS Remote Enclosure module lets one list a URL and MIME type for a file to be put into an enclosure tag on an RSS feed. It works fine and the iTunes Music Store recognizes my podcast appropriately. What it does not do is provide a user-friendly way to directly listen to the podcast entry. It's very convenient for a podcast to allow readers to directly play the podcast entry while reading the website. Usually this is done with a Flash based player.

The RSS Remote Enclosure module does not support this out of the box.

My site also has the Contemplate module installed and I could have made a template for blog entries which detected RSS Remote Enclosures. But I chose a different way.

In the module is a hook_nodeapi method. The nodeapi hook is called at various stages of processing a node, one of which is while the node is being prepared to be rendered in a browser. In the view action one can append items into $node->content and those items will be rendered in the browser.

This is approximately how this hook is used.

  case 'view':
$node->content['descriptive-tag'] = array(
'#value' => 'text to render',
'#weight' => '10'
);
break;

The descriptive-tag seems to be arbitrary so long as you're not using a tag name used by some other module. Since $node->content is an array the descriptive-tag allows for there to be multiple items to render. At the end of several hook_nodeapi($node, 'view'...) calls the $node->content should have one or more entries that, together, represent the content to render. But since it's an array there isn't an indication of what order to output the items. That's where the '#weight' values come in, weight being the ordering to use.

Next I wanted to find a free open source MP3 player. Found the one here: http://flash-mp3-player.net/ The web site has a convenient generator page that lets you enter a few values to make a player customized for your content. However in my case the player code has to be generated by the RSS Remote Enclosure fields in my podcast entries. Fortunately the code is very straightforward and I ended up with the following modification to the RSS Remote Enclosure module.

  case 'view':
if (variable_get(ENCL_REMOTE_RSS_LINK, false)) {
if ($teaser) {
$node->teaser .= _encl_remote_encl_link($encl_remote);
}
else {
$node->body .= _encl_remote_encl_link($encl_remote);
}
}
if ($encl_remote->mime_type == 'audio/mpeg') {
$node->content['remote_enclosure'] = array(
'#value' => '




',
'#weight' => '5',
);
}
break;

To be kind to http://flash-mp3-player.net/ I downloaded their SWF file to my server so that it's my bandwidth that's being used, not theirs. The important part of this is the two places where $encl_remote->url is used.

The part beginning with variable_get(... is the original code in the module. I haven't modified that part, and instead added code afterward.

Since this player only supports MP3 playback, the code checks $encl_remote->mime_type == 'audio/mpeg'.

The content of the '#value' entry is the code copied from the http://flash-mp3-player.net/ site. As I said, I downloaded their SWF file to my site and have given the correct URL for my copy. Next $encl_remote->url is given to the movie and FlashVars parameters. In the second case the URL is supposed to be encoded in the style made by the urlencode function. The '#weight' of 5 means it will be placed towards the end. I've also used a #weight of '-5' and it puts the player at the top of the page rather than at the bottom.