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.
<?php
/**
* Override flashvideo embed code
*/
function phptemplate_flashvideo_play_flash($video) {
// Initialize index variable used for multiple players if it doesn't exist
if (!$GLOBALS['flashvideo_embed_index']) { $GLOBALS['flashvideo_embed_index']=0; }
// increment index
$GLOBALS['flashvideo_embed_index']++;
// Get the FlashVars for this video.
$flashvars = flashvideo_get_flashvars($video);
// Creates an absolute path for the player.
$loader_path = check_url(file_create_url(flashvideo_variable_get($video['nodetype'], 'player', 'Player.swf')));
$image = str_replace('.flv', '.jpg', $video['file']);
$output .=<<<EOF
<div id="video-player-{$GLOBALS['flashvideo_embed_index']}"></div>
<script type="text/javascript">
var so = new SWFObject('/misc/mediaplayer.swf','mpl','450','357','8');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addVariable('displayheight','357');
so.addVariable('displaywidth','450');
so.addVariable('file','{$video['file']}');
so.addVariable('image', '{$image}');
so.addVariable('backcolor','0x000000');
so.addVariable('frontcolor','0xEEEEEE');
so.addVariable('lightcolor','0xFFFFCC');
so.addVariable('screencolor','0x000000');
so.addVariable('searchbar','false');
so.addVariable('showdigits', 'true');
so.write('video-player-{$GLOBALS['flashvideo_embed_index']}');
</script>
EOF;
return $output;
}
?>
This code is using the JW FLV Player, so your swf parameters may differ if you are using something else.
What if you have more than 1 video?
Great piece of code!
Very useful and works great. Is there a way to update the code so it works with multiple videos on the same page?
I'm using FlashVideo module as well and found if you have multiple videos, it won't display correctly because the code is outputting the same id for each Flash video.
Good Question!
I was only using 1 video per page.
Check out the updated code in the main article. I hate to use globals, but $video doesn't contain any unique data besides the file path.
I added an index variable that increments every time the theme function is called. The index is then added to the end of the div id.
i.e.
div id="video-player-1"
div id="video-player-2"
etc...
I haven't tested it with multiple players, but this should work. Let me know if you test it out.
Post new comment