<%@ webhandler language="C#" class="MediaHandler" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
public class MediaHandler : IHttpHandler
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
string sql = "SELECT * FROM Entry WHERE EntryID = '" + ctx.Request.QueryString["ID"] + "'";
SqlConnection connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True");
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{
ctx.Response.Clear();
ctx.Response.AddHeader("Content-Type", dr["EntryMediaMIMEType"].ToString());
ctx.Response.BinaryWrite((byte[])dr["EntryMedia"]);
}
redjenr
Member
19 Points
14 Posts
Streaming video from SQL Server to embedded player
Jun 25, 2007 12:33 AM|LINK
hi, im a noob and having a bit of a problem getting the stream to go to a player that i wrote into the page
this is my stream coming from sql server
protected void Page_Load(object sender, EventArgs e)
{
string sql = "SELECT EntryMedia, EntryMediaMIMEType FROM Entry WHERE EntryID = '4'";
SqlConnection connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True");
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.AddHeader("Content-Type", dr["EntryMediaMIMEType"].ToString());
Response.BinaryWrite((byte[])dr["EntryMedia"]);
}
dr.Close();
connection.Close();
}
works fine and dandy for popping open a media player and playing, but i want to open it in a player i put in the page...
<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="player" width="320" height="260">
<param name="src" value="<%=*** 'i dont know what goes here' ***%>" />
<param name="showcontrols" value="true" />
<param name="autostart" value="true" />
</object>
can anyone help me with this?
thanks
sql server asp.net c# video stream problem
redjenr
Member
19 Points
14 Posts
Re: Streaming video from SQL Server to embedded player
Jun 25, 2007 03:53 AM|LINK
ok have figured it out
This is the page that fills a grid with results found, with a link to FileHandler.ashx and a query attached ?ID= 'the record id'
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void Page_Load(Object sender, EventArgs e)
{
string sql = "SELECT * FROM Entry";
SqlConnection connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True");
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
FileList.DataSource = command.ExecuteReader();
FileList.DataBind();
connection.Close();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataGrid id="FileList" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateColumn HeaderText="Entry Name">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "EntryName")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Entry Media Type">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "EntryMediaMIMEType") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Entry Media">
<ItemTemplate>
<a href="FileHandler.ashx?ID=<%# DataBinder.Eval(Container.DataItem, "EntryID") %>">View File</a>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</div>
</form>
</body>
</html>
this is FileHandler.ashx, returns binary stream
<%@ webhandler language="C#" class="MediaHandler" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
public class MediaHandler : IHttpHandler
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
string sql = "SELECT * FROM Entry WHERE EntryID = '" + ctx.Request.QueryString["ID"] + "'";
SqlConnection connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True");
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{
ctx.Response.Clear();
ctx.Response.AddHeader("Content-Type", dr["EntryMediaMIMEType"].ToString());
ctx.Response.BinaryWrite((byte[])dr["EntryMedia"]);
}
dr.Close();
connection.Close();
}
}
this is video.aspx for displaying the video
<%@ Page Language="C#" %>
<%@Import Namespace="System.IO" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="player" width="320" height="260">
<param name="url" value="FileHandler.ashx?ID=4" />
<param name="showcontrols" value="true" />
<param name="autostart" value="true" />
</object>
</div>
</form>
</body>
</html>
thats the bones of it just need to make it dynamic instead of just harcoding ?ID=4
filehandler.ashx is just modified code from someone out there A BIG THANKS TO YOU!!!!!!
cheers
red
shingo83
Member
8 Points
6 Posts
Re: Streaming video from SQL Server to embedded player
Jan 31, 2008 07:39 AM|LINK
hi,
This is what i have been looking for on how to run a video file from SQL. But i dont really understand on the FileHandler.ashx.
Can explain on that a bit? or do u have any sample to this? Your help will be greatly appreciated. Thanks
mona.sandeep
Member
6 Points
6 Posts
Re: Streaming video from SQL Server to embedded player
Jan 06, 2009 11:30 AM|LINK
hii...
i want to display playlist in windows media player.
am unable to find the way. please help me