.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Developing and Using Custom Control in Asp.Net - A realtime scenario

Posted By:Gaurav Arora       Posted Date: April 28, 2009    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  
 

Some day ago, I have faced a little problem to show streaming contents on my Web-Projects, I have gone through many R & d's and then decided to write a custom control for the same, then I have written a custom control.

 

Here, the same, I want to share with you:

 

File Name : videoPlayer.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="videoPlayer.ascx.cs" Inherits="videoPlayer" %>

<asp:PlaceHolder ID="phError" runat="server" Visible="false">

<asp:Label ID="lblError" runat="server" ForeColor="Red" Text="Error" />

asp:PlaceHolder>

<asp:Table ID="tblPlayer" runat="server" BorderWidth="1">

<asp:TableRow>

<asp:TableCell>

<asp:Literal ID="ltVideo" runat="server" />

asp:TableCell>

asp:TableRow>

asp:Table>

 

Now, lets start to write code-behind as follows:

 

File Name : videoPlayer.ascx.cs

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class videoPlayer : System.Web.UI.UserControl

{

#region Properties to customize the Video/Audio Control

///

/// true:FullScreen, false:CustomSize

///

public Boolean isFullSize

{

set

{

ViewState["isFullSize"] = value;

}

get

{

if (ViewState["isFullSize"] != null)

return Convert.ToBoolean(ViewState["isFullSize"]);

else

return true;

}

}

///

/// Full url-path of Video/Audio

///

public String sourceUrl

{

set

{

ViewState["sourceUrl"] = value;

}

get

{

if (ViewState["sourceUrl"] != null)

return Convert.ToString(ViewState["sourceUrl"]);

else

return "http://www.video.com/myVideo.mpeg"; //Default video

}

}

///

/// width of player

///

public String width

{

set

{

ViewState["width"] = value;

}

get

{

if (ViewState["width"] != null)

return Convert.ToString(ViewState["width"]);

else

return "640";

}

}

///

/// Height of player

///

public String height

{

set

{

ViewState["height"] = value;

}

get

{

if (ViewState["height"] != null)

return Convert.ToString(ViewState["height"]);

else

return "480";

}

}

///

/// Custom message when player initializes

///

public String standByMessage

{

set

{

ViewState["standByMessage"] = value;

}

get

{

if (ViewState["standByMessage"] != null)

return Convert.ToString(ViewState["standByMessage"]);

else

return "Please wait while the player inializes...";

}

}

///

/// States whether media automatic starts or not

///

public Boolean autoStart

{

set

{

ViewState["autoStart"] = value;

}

get

{

if (ViewState["autoStart"] != null)

return Convert.ToBoolean(ViewState["autoStart"]);

else

return true;

}

}

///

/// -100 is fully left, 100 is fully right.

///

public String balance

{

set

{

ViewState["balance"] = value;

}

get

{

try

{

if (ViewState["balance"] != null)

return Convert.ToString(ViewState["balance"]);

else

return "0";

}

catch

{

return "0";

}

}

}

///

/// Position in seconds when starting.

///

public Int32 currentPosition

{

set

{

ViewState["currentPosition"] = value;

}

get

{

if (ViewState["currentPosition"] != null)

return Convert.ToInt32(ViewState["currentPosition"]);

else

return 0;

}

}

///

/// Show play/stop/pause controls

///

public Boolean showcontrols

{

set

{

ViewState["showcontrols"] = value;

}

get

{

if (ViewState["showcontrols"] != null)

return Convert.ToBoolean(ViewState["showcontrols"]);

else

return true;

}

}

///

/// Allow right-click

///

public Boolean contextMenu

{

set

{

ViewState["contextMenu"] = value;

}

get

{

if (ViewState["contextMenu"] != null)

return Convert.ToBoolean(ViewState["contextMenu"]);

else

return false;

}

}

///

/// Toggle sound on/off

///

public Boolean mute

{

set

{

ViewState["mute"] = value;

}

get

{

if (ViewState["mute"] != null)

return Convert.ToBoolean(ViewState["mute"]);

else

return false;

}

}

///

/// Number of times the content will play

///

public Int32 playCount

{

set

{

ViewState["playCount"] = value;

}

get

{

if (ViewState["playCount"] != null)

return Convert.ToInt32(ViewState["playCount"]);

else

return 1;

}

}

///

/// 0.5=Slow, 1.0=Normal, 2.0=Fast

///

public


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend