The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
How to:
1. Open MS Visual Studio and create a User Control file (*.ascx). Here, I will call it VideoWrapper
2. You will need to register the Microsoft Silverlight assembly. To do so just copy/paste following snippet:
<%@ Register assembly="System.Web.Silverlight" namespace="System.Web.UI.SilverlightControls" tagprefix="asp" %> |
3. Add the asp:MediaPlayer control
The file should look like this:
<%@ Control Language="C#"AutoEventWireup="true" CodeFile="VideoWrapper.ascx.cs" Inherits="VideoWrapper" %> |
<%@ Register assembly="System.Web.Silverlight" namespace="System.Web.UI.SilverlightControls" tagprefix="asp" %> |
<asp:MediaPlayer ID="mediaPlayer" runat="server" /> |
4. Now, for the code. Open the control's code-behind file.
4.1 We are going to use the Sitefinity LibraryManager to retrieve the needed items from the database, so add the following references:
using System; |
using Telerik.Cms.Engine.Data; |
using Telerik.Libraries.Data; |
using Telerik.Libraries; |
4.2 In order to make the new control more flexible you can create few custom properties like this:
public int PlayerHeight{ get; set;} |
public int PlayerWidth { get; set; } |
public string LibraryProvider { get; set; } |
public string LibraryName { get; set; } |
public string ItemGuidID { get; set; } |
Later, when the control is added to Sitefinity, these properties will be exposed directly in the CMS so you will be able to set them through the UI.
4.3 Now to the Page_Load event. The following code will stretch the Media Player:
this.mediaPlayer.Height = PlayerHeight; |
this.mediaPlayer.Width = PlayerWidth; |
the next lines are dedicated for retrieving the Video file from the database:
var manager = new LibraryManager(LibraryProvider); |
var libraries = manager.GetAllLibraries(); |
Now we need to get the item and set it as the MediaSource for the MediaPlayer:
foreach (var library in libraries) |
{ |
var currentLibrary = (Library)library; |
if (currentLibrary.Name == LibraryName) |
{ |
var lItems = currentLibrary.GetItems(); |
foreach(var it in lItems) |
{ |
var item = (CmsContentBase)it; |
if(item.ID.ToString()==ItemGuidID) |
mediaPlayer.MediaSource = item.UrlWithExtension; |
} |
} |
} |
The code above is simply searching for the specified library and the specified item in this library, then the item Url is set as the mediaPlayer.MediaSource.
Remember that the Url should also contain the Item's Extensions!
5. Save and Upload the new Control to Sitefinity.
That is all it takes.
If you want to use external data sources just expose on string property and set the Media Player's Media Sources to it.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.