Monday, August 4, 2008

A Simple VideoPlayer Custom COntrol - Uses in application

In my previous post, I have presented a Video Player Custom control which plays all type of streaming media. Now, here I am presenting a simple way to apply the same custom control in web application.

File Name : VideoPLayerCustomControl.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="VideoPLayerCustomControl.aspx.cs"
Inherits="VideoPLayerCustomControl" %>

<%@ Register TagPrefix="whPlayer" TagName= "vaPlayer" Src="~/videoPlayer.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>Video Player Using Custom Control</title>
<form id="form1" runat="server">
<div align="center">
<whPlayer:vaPlayer ID="videoPlayer" autoStart="true" runat="server" />
<br />
<asp:ValidationSummary id="valSumm" runat="server" />
<asp:Label ID="lblVideoName" Text="Enter Video Name" runat ="server" />
<asp:TextBox ID="txtVideoName" runat="server" EnableViewState="true" Text="D:\Videos\AVSEQ06.DAT" />
<asp:Button ID="btnPlayVide" runat="server" OnClick="btnPlayVide_Click" Text="Play Video" />
<asp:RequiredFieldValidator id="rfvtxtVideoName" ControlToValidate="txtVideoName" text="*" ErrorMessage="Please eneter Video to play" runat="server" />

File Name : VideoPLayerCustomControl.aspx.cs
/* This Example is a part of different
* examples shown in Book:
* C#2005 Beginners: A Step Ahead
* Written by: Gaurav Arora
* Reach at : */
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 VideoPLayerCustomControl : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
if (Request.QueryString["sourceUrl"] != null)
this.videoPlayer.sourceUrl = Convert.ToString(Request.QueryString["sourceUrl"]);

videoPlayer.autoStart = true;
videoPlayer.height = "300";
videoPlayer.width = "300";

protected void btnPlayVide_Click(object sender, EventArgs e)
Response.Redirect("videoplayercustomcontrol.aspx?sourceUrl=" + txtVideoName.Text);


Steps to run the application
1. Open VS2005
2. Select New Web application

3. Add new Page from existing pages and browse to attachment
4. Run the applcation by prssing F5


3. If not want to add new page just copy and paste the content from above, code(s)
4. Make sure all contents would be copied and then press F5

and then Enjoy the video...

No comments:

Post a Comment