VideoGallery.aspx
<div class="matter-area fl">
<h2>Videos</h2>
<p>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<object id="player" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"
height="170" width="300">
<param name="url" value='<%# "VideoHandler.ashx?videoid=" + Eval("id") %>'/>
<param name="showcontrols" value="true" />
<param name="autostart" value="true" />
<param name="controller" value="true" >
</object>
</ItemTemplate>
</asp:Repeater>
<br />
<a href="http://www.interoperabilitybridges.com/windows-media-player-firefox-plugin-download" id="firefox" runat="server">Install Windows Media Player Plugin for Firefox</a>
<br />
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<object width="300" height="170" id="Object1" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" >
<param name="URL" value='<%# "VideoHandler.ashx?videoid=" + Eval("id") %>'/>
<param name="captioningID" value="cc" />
<param name="AutoStart" value="true" />
<param name="AutoRewind" value="true" />
<embed type="application/x-mplayer2"
pluginspage = "http://www.microsoft.com/Windows/Mediaplayer/"
id="player1"
name="URL"
value='<%# "VideoHandler.ashx?videoid=" + Eval("id") %>'
height="170" width="300"
autostart="true">
</embed>
</object>
</ItemTemplate>
</asp:Repeater>
<br />
<a href="http://www.interoperabilitybridges.com/wmp-extension-for-chrome" id="chrome" runat="server">Install Windows Media Player Plugin for Chrome</a>
<br />
<asp:Repeater ID="Repeater3" runat="server">
<ItemTemplate>
<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="Object2" width="300" height="170">
<param name="URL" value='<%# "VideoHandler.ashx?videoid=" + Eval("id") %>'>
<param name="http://path_to_the_video">
<param name="AutoStart" value="1">
<param name="ShowControls" value="1">
<param name="ShowStatusBar" value="1">
<param name="ShowDisplay" value="1">
<param name="stretchToFit" value="1">
<embed type="application/x-mplayer2"
pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/"
height="170" width="300" src='<%# "VideoHandler.ashx?videoid=" + Eval("id") %>'
filename='<%# "VideoHandler.ashx?videoid=" + Eval("id") %>' autostart="1" showcontrols="1" showstatusbar="1" showdisplay="1">
</embed>
</object>
</ItemTemplate>
</asp:Repeater></p>
</div>
VideoGallery.aspx.cs
public void Load()
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from videos", con);
DataSet ds = new DataSet();
da.Fill(ds);
if (Request.Browser.Browser == "IE")
{
Repeater1.DataSource = ds;
Repeater1.DataBind();
Repeater2.Visible = false;
Repeater3.Visible = false;
firefox.Visible = false;
chrome.Visible = false;
}
else if (Request.Browser.Browser == "Firefox")
{
//Repeater2.DataSource = GetSpecificVideo(1);
//Repeater2.DataBind();
Repeater3.DataSource = ds;
Repeater3.DataBind();
Repeater1.Visible = false;
Repeater2.Visible = false;
firefox.Visible = true;
chrome.Visible = false;
//Repeater3.Visible = false;
}
else if (Request.Browser.Browser == "Chrome")
{
Repeater3.DataSource = ds;
Repeater3.DataBind();
Repeater1.Visible = false;
Repeater2.Visible = false;
firefox.Visible = false;
chrome.Visible = true;
}
con.Close();
}
VideoHandler.ashx
<%@ WebHandler Language="C#" Class="VideoHandler" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public class VideoHandler : IHttpHandler
{
string testid="", videoid;
public void ProcessRequest (HttpContext context)
{
string connectionString = ConfigurationManager.ConnectionStrings["SLMFConnection"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
videoid = context.Request.QueryString["videoid"];
SqlCommand cmd = new SqlCommand("SELECT video FROM videos WHERE id = @id", connection);
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt64(videoid );
try
{
connection.Open();
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);
if (reader.HasRows)
{
while (reader.Read())
{
// context.Response.ContentType = reader["videoname"].ToString();
context.Response.BinaryWrite((byte[])reader["video"]);
}
}
}
finally
{
connection.Close();
}
}
public bool IsReusable
{
get {
return false;
}
}
}
No comments:
Post a Comment