Second Life of a Hungarian SharePoint Geek

July 23, 2013

Creating a Flash Video Player For SharePoint using the built-in web parts – Version 2

Filed under: CQWP, jQuery, SP 2010 — Tags: , , — Peter Holpar @ 22:51

In my recent post I illustrated how to query a Flash (FLV) video player web part using the built-in Content Editor Web Part (CEWP) and some JavaScript. In the current post I will show you how to achieve the same with Content Query Web Part (CQWP) by altering the standard ItemStyle.xsl and the ContentQueryMain.xsl files.

For the prerequisites regarding the document library for the Flash files, Flowplayer and jQuery libraries read the previous post.

If you don’t have experience in customizing XSL style sheet files, I recommend you to read the following articles first:

How to: Customize XSL for the Content Query Web Part

Customizing the Content Query Web Part and Custom Item Styles

To be sure that our customizations do not interfere with any other web part, we do not edit the original XSL files. Instead, open your site with SharePoint Designer 2010, locate the XSL files above and create a copy of them for editing. I created a new folder called Custom in Style Library/XSL Style Sheets, and copied both files there.

image

First, open the ContentQueryMain.xsl file for editing. We need to have a video player object at the top of the web part if our custom item style VideoList is selected in the CQWP. To achieve this goal, we have to edit the OuterTemplate.Body template, however, in this case we face with a problem. The selected item style is not available in the OuterTemplate.Body template out of the box as a parameter. As a workaround, we should read the Style attribute of the first item in Rows. The remaining of the customizations is pretty simple.

Locate the OuterTemplate.Body template in the ContentQueryMain.xsl, and insert the code below after the declaration of the EndColumn variable.

Code Snippet
  1. <xsl:variable name="Style" select="$Rows[1]/@Style" />
  2. <xsl:choose>
  3.     <xsl:when test="$Style='VideoList'">
  4.         <xsl:text disable-output-escaping="yes">
  5.             <![CDATA[
  6. <script type="text/javascript" src="/_layouts/flowplayer/flowplayer-3.2.12.min.js"></script>
  7. <script type="text/javascript" src="/_layouts/jQuery/jquery-1.8.3.min.js"></script>
  8. <link rel="stylesheet" type="text/css" href="/_layouts/flowplayer/style.css"></link>
  9. <span><a style="display:block;width:520px;height:330px" class="VideoPlayer"></a></span>
  10. <script language="ecmascript" type="text/ecmascript">
  11.     function startClip(src, title) {
  12.       flowplayer().play([{url: src, title: title}]);
  13.     }
  14.     
  15.     $(document).ready(startScript);
  16.     
  17.     function startScript() {
  18.       flowplayer("a.VideoPlayer", "/_layouts/flowplayer/flowplayer-3.2.16.swf");
  19.     }
  20. </script>
  21. ]]>
  22.         </xsl:text>
  23.     </xsl:when>
  24. </xsl:choose>

Next, open ItemStyle.xsl and insert the code below as the last template:

Code Snippet
  1. <xsl:template name="VideoList" match="Row[@Style='VideoList']" mode="itemstyle">
  2.     <xsl:variable name="SafeLinkUrl">
  3.         <xsl:call-template name="OuterTemplate.GetSafeLink">
  4.             <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
  5.         </xsl:call-template>
  6.     </xsl:variable>
  7.     <xsl:variable name="DisplayTitle">
  8.         <xsl:call-template name="OuterTemplate.GetTitle">
  9.             <xsl:with-param name="Title" select="@Title"/>
  10.             <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
  11.         </xsl:call-template>
  12.     </xsl:variable>
  13.     <div class="item link-item" style="text-align:left;">
  14.         <a href="javascript:void(0)" title="{$DisplayTitle}" onclick="startClip('{$SafeLinkUrl}', '')">
  15.             <xsl:value-of select="$DisplayTitle"/>
  16.         </a>
  17.     </div>
  18. </xsl:template>

Save the changes in both files and publish a new version of them. Run IISRESET.

Add a new CQWP to your page, and set the properties according to the figures below. VideoLib1 is the document library that contains my Flash movies, you should select your own library there:

image

image

Export the web part, open it using a text editor, and alter the ItemXslLink, MainXslLink and Xsl properties to refer to the customized ItemStyle.xsl and the ContentQueryMain.xsl files. Delete the original web part from the page and import the altered one.

The outcome of the web part is very similar to the CEWP version in my previous post.

image

There is however a significant benefit of using a CQWP rather than a CEWP: in the first case you can easily configure your web part to query not only a single document library, but a whole web site (including subsites) or even a whole site collection for Flash movies. If you like, you can even configure the CQWP to group movie files by their location, like the name of the document library.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: