Monday, 15 July 2013

how to play video in asp.net

Design code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Client/Corporate/Master/CorporateClientMaster.master" AutoEventWireup="true" CodeFile="CorporateTvAdsView.aspx.cs" Inherits="Client_Corporate_Pages_CorporateTvAdsView" %>
<%@ Register Src="~/Client/Corporate/UserControls/UC_CorporateClientMenu.ascx" TagPrefix="UC"
    TagName="Menu" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  
    <table width="100%" style="height: 600px">
        <tr>
            <td width="15%" style="vertical-align: top">
                <UC:Menu ID="Menu" runat="server" />
            </td>
            <td width="5%" style="vertical-align: top">
                <img src="../../../Images/Corporate/sidebar_border.png" />
            </td>
            <td width="80%" style="vertical-align: top">
            <table width="100%">
            <tr>
            <td  align="left">
            <div style="border-left:solid 1px #525252; border-bottom:solid 1px #525252; border-top:solid 1px #525252; border-right:solid 1px #525252; height:480px">
             <asp:Literal ID="Literal1" runat="server"></asp:Literal>
             </div>
            </td>
            </tr>
            <tr>
            <td style="height:200px">
             <div style="border-left:solid 1px #525252; border-bottom:solid 1px #525252; border-top:solid 1px #525252; border-right:solid 1px #525252; height:200px">
            <asp:DataList ID="dlview" runat="server" Width="100%">
            <ItemTemplate>
            <table>
            <tr><td>
            <span style="font-size:12px">
              <%# DataBinder.Eval(Container.DataItem, "Ad_Title")%><br />
            </span>
           <span style="font-size:12px;">
            <asp:LinkButton ID="lbtview" runat="server" Text='<%#name(Eval("Image_Path").ToString())%>'
                    CommandArgument='<%#Eval("Image_Path") %>'
                    oncommand="lbtview_Command"></asp:LinkButton>
                    </span></td></tr>
            </table>
            </ItemTemplate>
            </asp:DataList>
            </div>
            </td>
            </tr>
            </table>
            </td>
            </tr>
            </table>
</asp:Content>

C# code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Client_Corporate_Pages_CorporateTvAdsView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Literal1.Text = GetWmaObject("../../../Video/Corporate/" + BusinessLayer.GetInstance.TvaddSelect().ToList().Where(b=>b.Status==true).First().Image_Path, false);
            fill();
        }
    }
    void fill()
    {
        var m = (from x in BusinessLayer.GetInstance.TvaddSelect() where x.Status == true select x).ToList();
        dlview.DataSource = m;
        dlview.RepeatColumns = m.Count;
        dlview.DataBind();

    }
    private string GetWmaObject(string sourceUrl, bool isFullSize)
    {
        string myObjectTag = "";
        sourceUrl = sourceUrl + "";
        sourceUrl = sourceUrl.Trim();
        if (sourceUrl.Length > 0)
        {
            //Continue.
        }
        else
        {
            throw new System.ArgumentNullException("sourceUrl");
        }

        string myWidthAndHeight = "";



        if (isFullSize)
        {
            myWidthAndHeight = "";
        }
        else
        {
            myWidthAndHeight = "width='880' height='480'";
        }
        myObjectTag = myObjectTag + "<object classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' id='player' " + myWidthAndHeight + " standby='Please wait while the object is loaded...'>";
        myObjectTag = myObjectTag + "<param name='url' value='" + sourceUrl + "' />";
        myObjectTag = myObjectTag + "<param name='src' value='" + sourceUrl + "' />";
        myObjectTag = myObjectTag + "<param name='AutoStart' value='true' />";
        myObjectTag = myObjectTag + "<param name='Balance' value='0' />"; //-100 is fully left, 100 is fully right.
        myObjectTag = myObjectTag + "<param name='CurrentPosition' value='0' />"; //Position in seconds when starting.
        myObjectTag = myObjectTag + "<param name='showcontrols' value='true' />"; //Show play/stop/pause controls.
        myObjectTag = myObjectTag + "<param name='enablecontextmenu' value='true' />"; //Allow right-click.
        myObjectTag = myObjectTag + "<param name='fullscreen' value='" + isFullSize.ToString() + "' />"; //Start in full screen or not.
        myObjectTag = myObjectTag + "<param name='mute' value='false' />";
        myObjectTag = myObjectTag + "<param name='PlayCount' value='1' />"; //Number of times the content will play.
        myObjectTag = myObjectTag + "<param name='rate' value='1.0' />"; //0.5=Slow, 1.0=Normal, 2.0=Fast
        myObjectTag = myObjectTag + "<param name='uimode' value='full' />"; // full, mini, custom, none, invisible
        myObjectTag = myObjectTag + "<param name='showdisplay' value='true' />"; //Show or hide the name of the file.
        myObjectTag = myObjectTag + "<param name='volume' value='50' />"; // 0=lowest, 100=highest
        myObjectTag = myObjectTag + "</object>";
        return myObjectTag;
    }
    protected void lbtview_Command(object sender, CommandEventArgs e)
    {
       this.Literal1.Text=GetWmaObject("../../../Video/Corporate/" + e.CommandArgument.ToString(),false);
    }
    public string name(string s)
    {
        string[] ss = s.Split('.');
        return ss[0];
    }
}
Page looks like :

No comments:

Post a Comment