play video from database in a datalist using generic handler.. [Resolved]

Posted by Shameer.Ali87 under ASP.NET on 2/4/2014 | Points: 10 | Views : 2629 | Status : [Member] | Replies : 2
hi all experts,

I have code to play videos from database, dynamically using handler,
here, while storing the videos in database, i have converted them into binary format,
my table design is as below - ID, Name, Data

my question is, i am not able to bind the binary format video file on to the player,

my handler code is as below
public void ProcessRequest(HttpContext context)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["constring"]);
SqlCommand cmd = new SqlCommand();

int id = int.Parse(context.Request.QueryString["id"]);
byte[] bytes=null;
string name;

try
{
cmd = new SqlCommand("select Name, Data from tbl_videos where Id=@Id", con);
cmd.Parameters.AddWithValue("@Id", id);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
bytes = (byte[])sdr["Data"];
name = sdr["Name"].ToString();
context.Response.BinaryWrite(bytes);
con.Close();
}

catch (Exception ex)
{
ex.Message.ToString();
}
}


I have a datalist databound event,

protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
/// here LnkVideoID is the id of link button
///(it is nothing but, iam getting list of videos from database,
///& up on click of linkbutton appropriate video will be played.)
LinkButton LnkVideoID = (LinkButton)e.Item.FindControl("LnkVideoID");

string GetID = LnkVideoID.CommandArgument;
string objid = "getvideo.ashx?ID=" + GetID;
Session["value"] = objid.ToString();
LnkVideoID.PostBackUrl = Session["value"].ToString();

}

my player code is as below,
<object id="objid" type="application/x-shockwave-flash" data="player_flv_multi.swf" width="540"
height="300">
<param name="movie" value="player_flv_multi.swf" />
<param name="allowFullScreen" value="true" />
<param name="FlashVars" value="<%= Session["value"].ToString()%>&amp;autoplay=1&amp;margin=3&amp;showstop=1&amp;showvolume=1&amp;showtime=1&amp;showfullscreen=1" />
</object>


any help will be thankfull..

shameer ali shaik


Responses

Posted by: Shameer.Ali87 on: 2/4/2014 [Member] Starter | Points: 25

Up
0
Down

Resolved
thanks for the links,
i got it, small change in my player code
                            <object id="objid" type="application/x-shockwave-flash" data="player_flv_multi.swf" width="540"
height="300">
<param name="movie" value="player_flv_multi.swf" />
<param name="allowFullScreen" value="true" />
<param name="FlashVars" value="flv=getvideo.ashx?Id=<%= Session["value"].ToString() %>&amp;autoplay=1&amp;margin=0&amp;showstop=1&amp;showvolume=1&amp;showtime=1&amp;showfullscreen=1" />
</object>

and then my data_bound function
        protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton LnkVideoID = (LinkButton)e.Item.FindControl("LnkVideoID");
string GetID = LnkVideoID.CommandArgument;
Session["value"] = GetID.ToString();
}

and i have added a item_command function, to play the videos as per the datalist items.


shameer ali shaik

Shameer.Ali87, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response