In this week's episode, Bob has changed his ways. He no longer robs liquor stores, beats up little kids, or uses the jQuery Media module to display podcast audio and video on his websites. Instead, he shows how awesome, flexible, and easy SWFTools is to implement. All on this week's Mustardseed video podcast!

// Don't add the javascript player stuff for certain devices/browser (e.g iPhone) if (!useragent_noplayer()) { // Create the javascript - there's some overkill in here and it's not been optimized - should move to using the Metadata Plugin $media_js = "if (Drupal.jsEnabled) {\n$(document).ready(function() {\n"; $media_js .= "$('#$media_class').media( { width: 290, height: 24, flashvars: {soundFile:'". $media['path_raw'] ."', bg:'0xA4B940', leftbg:'0x183C45', lefticon:'0xFFFFFF', righticon:'0xFFFFFF', rightbg:'0x86982F', text:'0xFFFFFF', slider:'0x183C45'} } );"; $media_js .= "\n});\n}"; drupal_add_js($media_js, 'inline', 'header'); }The above snippet references this function in template.php/** * Helper function for not adding the player for certain browsers/devices. */ function useragent_noplayer() { $agent = $_SERVER['HTTP_USER_AGENT']; $browsers = array('iPhone'); foreach ($browsers as $browser) { if (preg_match("/$browser/", $agent)) { return TRUE; } } return FALSE; }Just something to think about when you consider how many iPhones there are out there.<?php $filepath = 'http://example.com/myfile.mp3'; print swf($filepath); ?><?php if (!$status) { print " node-unpublished"; } ?>"> <?php print $title?> <?php print $node->field_media_description[0]['view'] ?> Music © <?php print $node->field_media_date[0]['view'] ?> <?php print $node->field_media_owner[0]['view'] ?> <?php // Displays the media player with an Imagefield preview and the Play icon turned off print swf($node->field_media[0]['filepath'], array( 'flashvars' => array( 'image' => 'media-image/' . ($node->field_media_image[0]['filename']), 'icons' => 'false') )); ?> <?php // Displays the music-only message if checked for this node $musiconly = $node->field_media_musiconly[0]['view']; if ($musiconly == 'musiconly') { print 'Music only, video not available'; } ?> <?php if (!$teaser): ?> <?php if ($links) { ?><?php print $links?><?php }; ?> <?php endif; ?> <?php if ($teaser): ?> <?php if ($links) { ?><?php print $links?><?php }; ?> <?php endif; ?>------------- Also, for the person who asked about showing multiple media files, here's how I display a separate player for each audio or video file in a multi-value field:<?php foreach ((array)$node->field_media as $item) { ?> <?php print swf($item['filepath']) ?> <?php } ?>I haven't figured out yet how to make a single-player playlist for multiple media files, but will share that when I do. Quick note to Bob: would it be possible to add the code formatting/box to comments here on the site? I previewed my post and noticed it's a bit hard to read the code. God bless :D<?php print swf($node->field_audio_file[0]['filepath']); ?>in a conditional statement so I had:<?php if ($field_audio_file): ?> <?php print swf($node->field_audio_file[0]['filepath']); ?> <?php endif; ?>So far this works fine. Let me know if you see any problems with this. I also had to go into the Display Fields setting for my node type and toggle this cck field to "Hidden" so I don't end up seeing the download link.<?php function phptemplate_preprocess_node(&$vars, $hook) { if ($vars['node']->type == 'media' && module_exists('swftools') && count($vars['field_media'])) { foreach($vars['field_media'] as $file) { $vars['content'] .= swf($file['filepath']); } } } ?>- Copy
- Make another copy of the file, and this time name it
- Edit
That's all there is to it. Now you don't have to create a custom theme for every new node type that has a podcast in it. More details are available at http://www.advantagelabs.com/drupal-colonoscopy-or-how-theme-cck-field-d...sites/all/modules/cck/theme/content-field.tpl.phptosites/all/themes/{yourtheme}/content-field.tpl.php. Very important: keep the same filename!sites/all/themes/{yourtheme}/content-field-podcast.tpl.php.sites/all/themes/{yourtheme}/content-field-podcast.tpl.phpto enable swf on the item. Replace<?php print $item['view'] ?>with<?php print swf($item['filepath'])?>.content-field-podcast.tpl.phpbutcontent-field-field_podcast.tpl.php