Play Video by Url Stored in Database

Dotnet4ashu
Posted by Dotnet4ashu under ASP.NET category on | Points: 40 | Views : 2437
Hi Experts

This is Very simple code

In Sql First create table

create table url_table
(
uid int identity(1,1),
url varchar(max)
)

in asp.net


Just take the Literal Control on aspx page

string VideoString;
Int64 uid;

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PropertyConn"].ConnectionString);

if (!IsPostBack == true)
{
// if (Request.QueryString["uid"] != null) ===============If Required
{
// uid = Convert.ToInt64(Request.QueryString["uid"]); =============== If Required

SqlCommand sqlcmd = new SqlCommand("select * from url_table where uid='" + uid + "'", con);
con.Open();

SqlDataReader dr = sqlcmd.ExecuteReader();
if (dr.Read())
{
VideoString = Convert.ToString(dr["video"]);
}


Literal1.Text = GetYouTubeScript(VideoString);

dr.Close();
con.Close();
}




}


}

protected string GetYouTubeScript(string id)
{
string scr = @"<object width='640' height='480'> ";
scr = scr + @"<param name='movie' value='https://www.youtube.com/v/" + id + "'></param> ";
scr = scr + @"<param name='allowFullScreen' value='true'></param> ";
scr = scr + @"<param name='allowscriptaccess' value='always'></param> ";
scr = scr + @"<embed src='https://www.youtube.com/v/" + id + "' ";
scr = scr + @"type='application/x-shockwave-flash' allowscriptaccess='always' ";
scr = scr + @"allowfullscreen='true' width='640' height='480'> ";
scr = scr + @"</embed></object>";
return scr;
}
}

Comments or Responses

Posted by: T.Saravanan on: 2/28/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Nice info. Kindly post your code inside the code tag.

Login to post response