Add the following in your application to show video (from database)
STEP-1
<object id=’player1′ enableviewstate=’false’ classid=’clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6′ visible=’true’
height=’500′ width=’500′><param name=’url’ value=’ShowImage.ashx?id=51’/><param name=’loop’ value=’false’ />
<param name=’showcontrols’ value=’true’ /></object>
Here (ShowImage.ashx?id=51′) 51 is taken as only example which is the primary key field of table of which video is to be retrieved.
|
STEP-2
|
<%@ WebHandler Language="C#" Class="ShowImage" %> public class ShowImage : IHttpHandler,IRequiresSessionState { Int32 picid; string conn = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString; /// Get all the pictures available public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (context.Request.QueryString["id"] != null) picid = Convert.ToInt32(context.Request.QueryString["id"]); Stream strm = ShowAlbumImage(picid); if (strm != null) { byte[] buffer = new byte[4096]; int byteSeq = strm.Read(buffer, 0, 4096); while (byteSeq > 0) { context.Response.OutputStream.Write(buffer, 0,byteSeq); byteSeq = strm.Read(buffer, 0, 4096); } } } ///<summary> ///<param name="picid">is the primary key of the video which is needed to show </param> ///<returns>image value is returned as memorystream</returns> public Stream ShowAlbumImage(int picid) { SqlConnection connection = new SqlConnection(conn); string sql = "SELECT pic FROM T_PHOTOS WHERE PK_ID = " + picid +""; //Datatype of pic is taken as varbinary(MAX) SqlCommand cmd = new SqlCommand(sql, connection); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@ID", picid); connection.Open(); object img = cmd.ExecuteScalar(); try { return new MemoryStream((byte[])img); } catch { return null; } finally { connection.Close(); } } public bool IsReusable { get { return false; } } }