FLV item display XSL

From VYRE

Jump to: navigation, search

Embeds an swfobject to play FLV files

The following example is based on the JW FLV player created by Jeroen Wijering, the available parameters may differ between players. The first version also makes use of SWFObject while the secondd version is based on entirely valid (X)HTML.

Version 1: Using JavaScript and SWFObject

Make sure you have created a FLV file service, and you have uploaded the SWFObject JS File. Uploaded the flv files that render the player to the other_files directory.

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="UTF-8"/>
  <xsl:param name="context_path"></xsl:param>
  <xsl:param name="current_path"></xsl:param>
  <xsl:param name="parent_path"></xsl:param>
  <xsl:template match ="/result/file-item">
  <xsl:choose>
    <xsl:when test="derived-files/all/file[@serviceType='preview_flv']">
     <!-- SWFOject JS file-->
     <script type="text/javascript" src="/generated_files/pub_module/script/s159.js"></script>
      <xsl:variable name="originalUrl" select="derived-files/all/file[@serviceType='preview_flv']"/>    
      &lt;p id="player">
        <a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.
      </p>
       <script type="text/javascript">
        var s1 = new SWFObject("/other_files/flashplayer/flvplayer_32.swf","single","480","360","7");
        s1.addParam("allowfullscreen","true");
        s1.addParam("allowScriptAccess","sameDomain");
        s1.addVariable("file","<xsl:value-of select='$originalUrl' disable-output-escaping='yes' />".split("&").join("%26"));
        s1.addVariable('height','360');
        s1.addVariable('width','480');
        s1.addVariable("lightcolor","0xff0000");
        s1.addVariable('overstretch','true');
        s1.write("player");
      </script>
    </xsl:when>
    <xsl:otherwise>
    <img src="/other_files/general/nopreview_small.gif" alt = "{name}" title ="{name}"/>
    </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
</xsl:stylesheet>

Version 2: Using Cross browser valid (X)HTML

The below is an XSL template that requires two parameters, the video, in this case your FLV file service, and thumbnail to display when the video is not playing. Both parameters need to be URL encoded, which can be done with this template for URL Encoding With XSL.

The method is based on Ian Hickson's double nested object method and is adapted to XSL with the downlevel revealed conditional comment that hides the nested object from Internet Explorer.

  <xsl:template name="flash-video">
  	<xsl:param name="video" />
  	<xsl:param name="thumbnail" />
  	<xsl:variable name="flashvars">file=<xsl:value-of select="$video"/>&amp;type=flv&amp;overstretch=true&amp;usefullscreen=false&amp;image=<xsl:value-of select="$thumbnail"/></xsl:variable>
  	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
	        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
	        width="200" height="200">
	  <param name="movie" value="/other_files/flv/mediaplayer.swf" /> 
	  <param name="quality" value="high" />
	  <param name="bgcolor" value="#FFFFFF" />
	  <param name="flashvars" value="{$flashvars}" />
	  <xsl:comment><![CDATA[[if IE]><![if !IE]><![endif]]]></xsl:comment>
	  <object data="/other_files/flv/mediaplayer.swf"
	          width="200" height="200" type="application/x-shockwave-flash">
	    <param name="quality" value="high" />
	    <param name="bgcolor" value="#FFFFFF" />
	    <param name="pluginurl" value="http://www.macromedia.com/go/getflashplayer" />
	    <param name="flashvars" value="{$flashvars}" />
	    <p><a href="http://www.macromedia.com/go/getflashplayer">Please download the latest flash player.</a></p>
	  </object>
	  <xsl:comment><![CDATA[[if IE]><![endif]><![endif]]]></xsl:comment>
	</object>
  </xsl:template>
Personal tools