CS Spotlight: Video Gallery
A couple of folks have begun to notice The Hive and have been asking how to build a hive-like video gallery on the Community Server forums. In this week's spotlight, I figured I'd answer some of those questions.
In case you weren't aware, CS comes with a video listing page as part of the forums. Just browse to /forums/videos.aspx and you'll see something that looks similar to the Active/Unanswered/Not Read pages. This page uses a ThreadView to display a text-based listing of threads containing videos. In order to get more of a GoogleVideo look, we've also included a ThreadDataList control. Similar to the ThreadRepeater, the ThreadDataList control exposes an item template for you to customize. Enough theory, let's get to some code.
Replace the <CSD:ThreadView /> control with the following:
<div id="VideoGallery" align="center">
<CSD:ThreadDataList ThreadViewMode="Videos" runat="server" CellPadding="20" RepeatColumns="3" RepeatDirection="Horizontal">
<ItemTemplate>
<div id="VideoItem" style="text-align: center">
<div id="Video">
<a href="<%# Globals.GetSiteUrls().Post((int)DataBinder.Eval(Container.DataItem, "PostID")) %> "><img src="<%# DataBinder.Eval(Container.DataItem, "VideoImageUrl") %>" width="200" height="150" border="0" /></a>
</div>
<div id="Subject">
<a href="<%# Globals.GetSiteUrls().Post((int)DataBinder.Eval(Container.DataItem, "PostID")) %> "><%# Formatter.CheckStringLength(DataBinder.Eval(Container.DataItem, "Subject").ToString(), 35) %></a>
</div>
<div id="Statistics">
<%# string.Format(ResourceManager.GetString("PostDisplay_VideoPost_Statistics"), DataBinder.Eval(Container.DataItem, "Views"), DataBinder.Eval(Container.DataItem, "Replies")) %>
</div>
<div id="Details">
<%# string.Format(ResourceManager.GetString("PostDisplay_VideoPost_Details"), DataBinder.Eval(Container.DataItem, "VideoFileFormat"), DataBinder.Eval(Container.DataItem, "VideoDuration")) %>
</div>
</div>
</ItemTemplate>
</CSD:ThreadDataList>
</div>
Now let's walk thru what we've done.
<div id="VideoGallery" align="center">
First you'll notice we placed everything in a centered div. This will keep your gallery centered. (You can use CSS to your heart's content, but I'm gonna keep it simple)
<CSD:ThreadDataList ThreadViewMode="Videos" runat="server" CellPadding="20" RepeatColumns="3" RepeatDirection="Horizontal">
Since the ThreadDataList is a subclass of DataList, you have all the properties of a regular DataList available. I've chosen to have a three-column horizontal based flow layout (with some padding)
<div id="VideoItem" style="text-align: center">
<div id="Video">
<a href="<%# Globals.GetSiteUrls().Post((int)DataBinder.Eval(Container.DataItem, "PostID")) %> "><img src="<%# DataBinder.Eval(Container.DataItem, "VideoImageUrl") %>" width="200" height="150" border="0" /></a>
</div>
<div id="Subject">
<a href="<%# Globals.GetSiteUrls().Post((int)DataBinder.Eval(Container.DataItem, "PostID")) %> "><%# Formatter.CheckStringLength(DataBinder.Eval(Container.DataItem, "Subject").ToString(), 35) %></a>
</div>
<div id="Statistics">
<%# string.Format(ResourceManager.GetString("PostDisplay_VideoPost_Statistics"), DataBinder.Eval(Container.DataItem, "Views"), DataBinder.Eval(Container.DataItem, "Replies")) %>
</div>
<div id="Details">
<%# string.Format(ResourceManager.GetString("PostDisplay_VideoPost_Details"), DataBinder.Eval(Container.DataItem, "VideoFileFormat"), DataBinder.Eval(Container.DataItem, "VideoDuration")) %>
</div>
</div>
This is where we've specified what each video "chunk" should look like. I've tried to keep it simple in order to see how you would best access the data that's available. If you're familiar with databinding syntax, you'll just need to understand the properties available on a video post. For this sample we'll access the PostID (used for url generation), the VideoImageUrl (used as the src for a preview image), the Subject (used as the title), Views & Replies (used for stats), and VideoFileFormat & VideoDuration (used for details). If you look closely you'll see that we're using Formatter.CheckStringLength to guarantee that long subjects don't make the UI look awful. We're also using String.Format to compose the statistics and details text. By changing the data, layout, css, or the resources, you have ultimate control for how you want your video gallery to look.
Extra Credit
If you want to bee more hive-like (sorry, couldn't resist), you can also create a new navigation tab, master page, and change the siteurl in order to make videos a first-class citizen. That exercise, however, is left to the reader... :)
Before and After
Here are some pictures of what the /forums/videos.aspx page looks like before and after this tweak.