coder1.com

  • home
  • drupal articles
  • contact
Home

Theming the Drupal flashvideo module with swfobject.

Mike Milano — June 22, 2008 - 11:37pm

[img_assist|nid=11|title=|desc=|link=none|align=right|width=87|height=100]The FlashVideo module is great, but you may want to embed the video with swfobject, so here's one way to do it.

Of course for this to work you're going to need to include swfobject.js in your template. How you do that depends on your theme and is a little beyond the scope of this article.

Once you have that setup, you just need to open up template.php and add ths theme override function.

  1. <?php
  2. /**
  3.  * Override flashvideo embed code
  4.  */
  5. function phptemplate_flashvideo_play_flash($video) {
  6.  
  7. // Initialize index variable used for multiple players if it doesn't exist
  8. if (!$GLOBALS['flashvideo_embed_index']) { $GLOBALS['flashvideo_embed_index']=0; }
  9.  
  10. // increment index
  11. $GLOBALS['flashvideo_embed_index']++;
  12.  
  13. // Get the FlashVars for this video.
  14. $flashvars = flashvideo_get_flashvars($video);
  15. // Creates an absolute path for the player.
  16. $loader_path = check_url(file_create_url(flashvideo_variable_get($video['nodetype'], 'player', 'Player.swf')));
  17. $image = str_replace('.flv', '.jpg', $video['file']);
  18.  
  19. $output .=<<<EOF
  20.   <div id="video-player-{$GLOBALS['flashvideo_embed_index']}"></div>
  21.   <script type="text/javascript">
  22.   var so = new SWFObject('/misc/mediaplayer.swf','mpl','450','357','8');
  23.   so.addParam('allowscriptaccess','always');
  24.   so.addParam('allowfullscreen','true');
  25.   so.addVariable('displayheight','357');
  26.   so.addVariable('displaywidth','450');
  27.   so.addVariable('file','{$video['file']}');
  28.   so.addVariable('image', '{$image}');
  29.   so.addVariable('backcolor','0x000000');
  30.   so.addVariable('frontcolor','0xEEEEEE');
  31.   so.addVariable('lightcolor','0xFFFFCC');
  32.   so.addVariable('screencolor','0x000000');
  33.   so.addVariable('searchbar','false');
  34.   so.addVariable('showdigits', 'true');
  35.   so.write('video-player-{$GLOBALS['flashvideo_embed_index']}');
  36.   </script>
  37. EOF;
  38.  
  39. return $output;
  40. }
  41. ?>

This code is using the JW FLV Player, so your swf parameters may differ if you are using something else.

  • Drupal
  • FLV
  • Module

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <img> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h5> <h6> <h7>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Poll

Have you checked out Drupal 7 yet? (still alpha):

User login

  • Request new password

Navigation

  • Recent posts
  • home
  • drupal articles
  • contact