Some time we need to play video on our website or software.In this article, I am going tell you that, how can we store video on server and play according to our requirement. RTMP(rtmp) is a protocol like as HTTP for play video through FMS Server.
First of all we will design our database and table-
Step-1: Create table
CREATE TABLE
[dbo].[Video](
[stockid] [int] IDENTITY(1,1) NOT NULL,
[videoname] [nvarchar](150) NULL,
[VideoIp] [nvarchar](150) NULL,
CONSTRAINT
[PK_Video] PRIMARY KEY
CLUSTERED
(
[stockid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS
= ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Step-2: Create Store procedure
Create PROCEDURE
[dbo].[spmaster]
@Action
VARCHAR(100)='',
@videoname
nvarchar(150)='',
@VideoIp
nvarchar(150)=''
if(@Action='insertvideotostock')
begin
insert into
dbo.Video_Stock (videoname,VideoIp) values(@videoname,@VideoIp)
end
if(@Action='getallvideostock')
begin
select * from Video
end
Step 3: Video.aspx page
<pre lang="HTML"><pre lang="HTML"></pre><%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="Video.aspx.cs"
Inherits="Video"
%>
<%@ Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="asp"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"
runat="server">
<title></title>
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=80);
opacity: 0.8;
z-index: 10000;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div id="GrdSubject" class="fontclass" runat="server">
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>
<fieldset class="fieldset"><legend>Manage Video Stock</legend><table><tr><td>
<asp:GridView ID="gvDetails" runat="server"
AutoGenerateColumns="False" CssClass="mGrid"
PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt"
ShowFooter="True"
onrowcommand="gvDetails_RowCommand" EnableModelValidation="True"
PageSize="25">
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:ImageButton ID="imgbtnAdd" runat="server" ImageUrl="Images/AddNewitem.png" CommandName="AddNew"
Width="30px"
Height="30px"
ToolTip="Add new
Topic" ValidationGroup="validaiton" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField
><ItemTemplate><asp:label ID="lblvideoname"
runat="server" Text='<%#Eval("videoname") %>'></asp:label></ItemTemplate>
<EditItemTemplate><asp:TextBox ID="txteditvideo" runat="server" Width="70px" Text='<%#Eval("videoname") %>'></asp:TextBox></EditItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
<HeaderTemplate><asp:TextBox ID="txtvideo" runat="server" Width="70px"></asp:TextBox>
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField
><ItemTemplate><asp:ImageButton ID="imgvideo"
runat="server"
ImageUrl="~/Images/video.jpg"
CommandName="Video"
CommandArgument='<%#Eval("VideoIp") %>' /></ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" /><EditItemTemplate><asp:TextBox ID="txteditvideoip" runat="server" Width="70px" Text='<%#Eval("VideoIp") %>'></asp:TextBox></EditItemTemplate>
<HeaderTemplate><asp:TextBox ID="txtvideoa" runat="server" Width="70px"></asp:TextBox>
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#61A6F8" Font-Bold="True" ForeColor="White" />
<PagerStyle />
</asp:GridView></td></tr></table>
<asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="btnShowPopup"
PopupControlID="pnlpopup" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" Width="700px" Style="display: none">
<table>
<tr>
<td align="right">
<asp:Image ID="btnCancel" ImageUrl="~/Images/canceel.png" runat="server"
/>
</td>
</tr>
<tr>
<td>
<table width="100%"
style="border: Solid 3px #61625d; width: 100%; height: 100%;
background:
#ffffff; padding: 0px;" cellpadding="0"
cellspacing="0">
<tr>
<td align="right"
style="width: 450px; padding: 0px;">
<object width='640' height='377' id='StrobeMediaPlayback'
name='StrobeMediaPlayback'
type='application/x-shockwave-flash'
classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'
>
<param name='movie' value='swfs/StrobeMediaPlayback.swf' />
<param name='quality' value='high' /> <param name='bgcolor' value='#000000' />
<param name='allowfullscreen' value='true' />
<param name='flashvars' value= '&src=<%=video %>&autoHideControlBar=true&streamType=recorded&autoPlay=true&verbose=true'/>
<embed src='swfs/StrobeMediaPlayback.swf' width='640' height='377' id='StrobeMediaPlayback'
quality='high' bgcolor='#000000' name='StrobeMediaPlayback'
allowfullscreen='true'
pluginspage='http://www.adobe.com/go/getflashplayer'
flashvars='&src=<%=video %>&autoHideControlBar=true&streamType=recorded&autoPlay=true&verbose=true'
type='application/x-shockwave-flash'>
</embed>
</object>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Panel>
</fieldset></ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html></pre>
Step 4: Video.cs
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data.SqlClient;
using
System.Collections;
using System.Data;
public partial class Default2 : System.Web.UI.Page
{
ConnectionString
cacon = new ConnectionString();
ConnectionString
kpcon = new ConnectionString();
DataSet ds = new
DataSet();
DataTable dt = new
DataTable();
Hashtable hst = new
Hashtable();
PagedDataSource
pagedData = new PagedDataSource();
PagedDataSource
pagedData1 = new PagedDataSource();
public string video;
protected void Page_Load(object
sender, EventArgs e)
{
if
(!IsPostBack)
{
bindtopic();
}
}
//Bind Video to
Gridview
public void bindtopic()
{
hst.Clear();
dt.Clear();
hst.Add("Action",
"getallvideostock");
ds = cacon.GetDataSet("[spmaster]", hst);
if
(ds.Tables[0].Rows.Count > 0)
{
gvDetails.DataSource = ds;
gvDetails.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gvDetails.DataSource = ds;
gvDetails.DataBind();
int
columncount = gvDetails.Rows[0].Cells.Count;
gvDetails.Rows[0].Cells.Clear();
gvDetails.Rows[0].Cells.Add(new TableCell());
gvDetails.Rows[0].Cells[0].ColumnSpan = columncount;
gvDetails.Rows[0].Cells[0].Text = "No Records Found";
}
}
protected void gvDetails_RowCommand(object
sender, GridViewCommandEventArgs e)
{
if
(e.CommandName.Equals("AddNew"))
{
TextBox
txtsession = (TextBox)gvDetails.HeaderRow.FindControl("txtsession");
TextBox
txtvideoname = (TextBox)gvDetails.HeaderRow.FindControl("txtvideo");
TextBox
txtvideoip = (TextBox)gvDetails.HeaderRow.FindControl("txtvideoa");
string
FileName = string.Empty, sValidImage = string.Empty, Msg = string.Empty,
sExe = string.Empty, sSavePath = string.Empty;
//
ImgUser.ImageUrl = "userphoto/" + FileName + sExe;
hst.Clear();
dt.Clear();
hst.Add("Action", "insertvideotostock");
hst.Add("session", txtsession.Text.ToString());
hst.Add("videoname",
txtvideoname.Text.ToString());
hst.Add("VideoIp", txtvideoip.Text.ToString());
hst.Add("pdffile", FileName);
Msg = GetDataset("spmaster", hst));
}
if
(e.CommandName == "Video")
{
video =
e.CommandArgument.ToString();
ModalPopupExtender1.Show();
}
}
}
CS Class:
string constr
= ConfigurationManager.ConnectionStrings["Connectionstring"].ToString();
SqlConnection con = new SqlConnection();
SqlCommand cmd = new
SqlCommand();
SqlDataAdapter adpt = new SqlDataAdapter();
public DataSet
GetDataSet(string spName, Hashtable hst)
{
con = new
SqlConnection();
cmd = new
SqlCommand();
con.ConnectionString = constr;
cmd.Connection = con;
cmd.CommandType =
CommandType.StoredProcedure;
cmd.CommandText = spName;
con.Open();
if (hst
!= null)
if
(hst.Count > 0)
AttachParameters(cmd, hst);
DataSet dataset = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(dataset);
con.Close();
return
dataset;
}
private void AttachParameters(SqlCommand command, Hashtable
hstParameters)
{
try
{
IEnumerator parameters =
hstParameters.Keys.GetEnumerator();
while
(parameters.MoveNext())
{
SqlParameter param = new SqlParameter();
param.ParameterName = "@" + parameters.Current;
param.Value =
hstParameters[parameters.Current];
command.Parameters.Add(param);
}
}
catch (Exception exception)
{
HttpContext.Current.Response.Write("Error : " + exception.Message + " </br> Source : " +
exception.Source);
}
}
For running this code we need some swfs file. Please you can download from there and use this file in root of your project.Download swf file
No comments:
Post a Comment