Video player in custom control
Hello All,
I am very new to sitefinity and have been tasked with creating a custom control in Visual Studio 2010 for use on a sitefinity implementation. One of the requirements is that the custom control play a video. Can anyone tell me how I can add the media player from sitefinity to the ascx file of my custom control and play a movie that is part of the data module I have created for the site? Sample code would be much appreciated.
Thanks very much,
Bill
Hi Bill,
It really depends on what kind of media you want to playback?
I think that if you could implement like a HTML5 player, you should go for that. For example you could use the JWPlayer or JPlayer. Depending on how you set up your data module, you could use the Sitefinity API to get the right media files and link them to one of these players.
If you need the Silverlight player from Sitefinity, you can just add it inside a UserControl and bind it from e.g. code-behind.
VideoPlayer.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VideoPlayer.ascx.cs" Inherits="SitefinityWebApp.Widget.Videos.VideoPlayer" %>
<%@ Register Namespace="Telerik.Sitefinity.Modules.Libraries.Web.UI.Videos" TagPrefix="sf" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sitefinity" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" %>
<
sitefinity:ResourceLinks
id
=
"resourcesLinks"
runat
=
"server"
>
<
sitefinity:ResourceFile
Name
=
"Telerik.Sitefinity.Resources.Scripts.Silverlight.js"
Static
=
"true"
/>
</
sitefinity:ResourceLinks
>
<
sf:MediaPlayerControl
ID
=
"mediaPlayer"
runat
=
"server"
></
sf:MediaPlayerControl
>
using
System;
using
System.Linq;
using
SitefinityWebApp.Base;
using
Telerik.Sitefinity.Modules.Libraries;
namespace
SitefinityWebApp.Widget.Videos
public
partial
class
VideoPlayer : WidgetBaseClass
protected
override
void
OnPreRender(EventArgs e)
Telerik.Sitefinity.Web.RouteHelper.SetUrlParametersResolved(
true
);
base
.OnPreRender(e);
// Get route data
var urlParameterString = System.Web.UI.ControlExtensions.GetUrlParameterString(
this
,
true
).Substring(1);
if
(urlParameterString ==
"undefined"
)
return
;
var video = LibrariesManager.GetManager().GetVideos().FirstOrDefault(x => x.UrlName == urlParameterString);
if
(video !=
null
)
mediaPlayer.MediaContentId = video.Id;
mediaPlayer.MediaUrl = video.MediaUrl;
mediaPlayer.AutoPlay =
true
;
Page.Title = video.Title;
Daniel,
Thanks for the reply. I am tearing my hair out here. I have no idea what I am doing wrong as I have almost no experience with SiteFinity. How can I post my code so that you could look at it and tell me where I am messing up?
Thanks,
Bill
Hey Bill,
You can put in inside a post to this thread, or just mail me at: daniel (at) damar dot nl.
Either way is fine.
Kind regards,
Daniel
Daniel,
Thank you. I just got the video to display in the MediaPlayerControl about 45 minutes ago. My only remaining issue at this point.
1: Hide the slider on the MediaPlayerControl so that the users can not fast forward through the video.
2: Trap and respond in my code behind to an event that should be fired when the playback of the video is completed.
I am doing the code behind in VB.
Any help would be greatly appreciated.
Thanks again
Hello Bill,
In order to help you you could open a support ticket, send us your control and some detailed information about it.
Thank you Danie for sharing your solutions.
Regards,
Stefani Tacheva
Telerik