I would up creating a snippet for this with a chunk, a TV and an IF instance to pull this off:
First, I created a boolean TV [[*LoadFlowPlayer]] to indicate if the page in question should load the javascripts [in the head] required to display the videos.
Second,I created the if instance in the head of the document to only Load the javascript if the LoadFlowPlayer TV is true
[[!If? &subject=`[[*LoadFlowPlayer]]` &operator=`eq` &operand=`true` &then=`[[$FlowplayerJS]]` ]]
Third, I created the javascript chunk [[$FlowPlayerJS]] and pasted my javascript in there:
<script type="text/javascript" src="/assets/flowplayer/flowplayer-3.1.4.min.js"></script>
Fourth, I setup some system variables to hold some default values for the snippet parameters, since most of the videos are in the same location & of the same size...
Finally, I created the [[ShowVideo]] snippet:
<?php
/*
[[!ShowVideo?
&path=`_file-name_` // REQUIRED! include the full path to the file i.e. /_folder_/_sub-folder_/_file-name_
&width=`480` // default, not required
&height=`360` // default, not required
&autoplay=`false` // default, not required
&autobuffer=`true` // default, not required
&url=`_repository-url_` // default, not required
]]
*/
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$videoid = '';
for ($p = 0; $p < 25; $p++) {
$videoid .= $characters[mt_rand(0, strlen($characters))];
}
if (!isset($width)){ $width = $modx->getOption('flowplayer_width'); }
if (!isset($height)){ $height = $modx->getOption('flowplayer_height'); }
if (!isset($autoplay)){ $autoplay = $modx->getOption('flowplayer_autoplay'); }
if (!isset($autobuffer)){ $autobuffer = $modx->getOption('flowplayer_autobuffer'); }
if (!isset($url)){ $url = $modx->getOption('amazon_url'); }
if (isset($path)){
$video = 'http://' . $url . '/' . $path;
$divstyle = 'margin:0 auto;width:'.$width.'px;height:'.$height.'px';
$hrefstyle = 'style="display:block;width:'.$width.'px;height:'.$height.'px;"';
$flowplayer = '<div class="video-player" style="'.$divstyle.'"><a href="'.$video.'" '.$hrefstyle.' id="' . $videoid . '"></a></div>';
$javascript = '<script> flowplayer("' . $videoid . '", "/assets/flowplayer/flowplayer-3.1.5.swf", {clip: {autoPlay:' . $autoplay . ',autoBuffering:' . $autobuffer . '}});</script>';
echo $flowplayer;
echo $javascript;
}else{
echo "error - no video file specified!";
}
So it works quite well and allows me to post multiple videos per page & best of all the user only really needs to learn the minimum tag to insert, which is: [[!ShowVideo? &path=`filename` ]]
The php probably could use some love, but what I still have questions about is my method of retrieving the system variables
$modx->getOption('flowplayer_width');
Is there a better/sexier way to do that? it just feels inefficient...
-thanks
-sean