Tuesday, February 26, 2008

Creating a Web streaming movie pager using C# and javascript- Sanjeewa Sapumana

//play a movie
//java script windows media player calling by java script
function SetMovie(mpath)

{
//var mediaName="myVideoName";
alert("Declared variables");

if (mpath == " ")
{
alert("apath is a empty");
}

else

document.getElementById('VideoPlayer').URL=mpath;
alert(document.getElementById('VideoPlayer').URL);
document.getElementById('VideoPlayer').controls.play();


alert("now video is playing");
return false;
}

//Defining the windows media player object in html code

< object type="application/x-oleobject" width="421" height="248" id="VideoPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
< param name="autostart" value="True" / >
< param name="showcontrols" value="false" / >
//in this case wer taking the url from the datagr id link list
< !--< param name="src" value="MediaFiles//YourMovie.wmv" / >-- >
< /object >


//datra grid databinding
protected void gvAvailableVideos_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lbtnVideoFile = ((LinkButton)e.Row.Cells[0].FindControl("lbtnVideoFile"));
if (lbtnVideoFile != null)
{
lbtnVideoFile.Text = gvAvailableVideos.DataKeys[rowno]["VideoFileName"].ToString();
DataView dv = DsMediaFiles.Tables[0].DefaultView;
dv.Sort = "id";
int rowId = dv.Find(gvAvailableVideos.DataKeys[rowno]["Id"]);
string VideoPath=string.Empty;
if(rowId != -1)
{
VideoPath = dv[rowId]["VideoPath"].ToString();
lbtnVideoFile.Attributes.Add("OnClick", "return SetMovie('" + VideoPath + "')");
}

}
rowno += 1;
}


//datagrid handiling html view

< asp:GridView ID="gvAvailableVideos" runat="server" Width="100%" AllowPaging="True" OnRowDataBound="gvAvailableVideos_RowDataBound" AutoGenerateColumns="False" DataKeyNames="Id,VideoFileName" >
< Columns >
< asp:TemplateField HeaderText="VideoFileName" >
< ItemTemplate >
< asp:LinkButton ID="lbtnVideoFile" CommandArgument='< %# Eval("VideoFileName")% >' runat="server" > </asp:LinkButton >
< /ItemTemplate >
< /asp:TemplateField >
< asp:BoundField DataField="AttachmentName" HeaderText="Attachment Name" / >
< /Columns >
< /asp:GridView >

No comments: