Reputation: 308
protected void Button2_Click(object sender, EventArgs e)
{
UploadLogic bl = new UploadLogic();
input = ListBox1.SelectedIndex >= 0 ? ListBox1.SelectedItem.ToString() : "";
DataSet ds = new DataSet();
ds = bl.Content_details(input);
if (ds.Tables[0].Rows.Count > 0)
{
Byte[] bytes = (Byte[])ds.Tables[0].Rows[0].ItemArray.GetValue(3);
Response.Buffer = true;
Response.Charset = "utf-16";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
Response.ContentType = ds.Tables[0].Rows[0].ItemArray.GetValue(2).ToString();
Response.AddHeader("content-disposition", string.Format("File_Path; filename={0}", input));
Response.OutputStream.Write(bytes, 0, input.Length);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
else
{
Label1.Text = "No File Found..!";
}
}
I wrote this code, but it only downloads the file from the database. If I want to play audio and video, then how can I do it?
Upvotes: 2
Views: 11580
Reputation: 95
just add this tag to your web page.
scrolling="no" frameborder="0" marginheight="0" marginwidth="0">name
to music
Upvotes: 0
Reputation: 66641
First of all in you code you just get and send the file (video or audio) and you think that the browser knows what to do with. The browser from the other side is going to decide in two thinks, one to show/play in a full page what you send, or just ask for download. Because is find the File_Path, is decide to ask the user for the download.
Now how to actually play an audio or a video to web page. Most of browsers until now is not support the direct play of an audio/video and the solution to that is the use of the adobe flash player. Using a player that is made on adobe you can send it to it a video/audio file (to the correct format) and he can play it. Also the Microsoft silverlight can do the same.
Now with the new browsers and html 5, you can direct play audio and video on a page.
So its up to you to decide what way you going to follow, flash,silverlight,html5.
Some examples:
http://www.w3schools.com/html/html_videos.asp
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_video_html5_4
http://www.web-video-player.com/
http://jplayer.org/latest/demos/
http://slvideoplayer.codeplex.com/
http://openvideoplayer.sourceforge.net/
http://www.longtailvideo.com/players/jw-wmv-player/
let see this part of code:
<embed width="320" height="240" src="movie.swf">
in this code the movie.swf
is the file that you like to play. To direct get it from database what you must do is to change that to a handler and from that handler you send this file.
<embed width="320" height="240" src="loadmovie.ashx?movie.swf">
Now inside the loadmovie.ashx
you run your code that reads the movie/audio from the database and then send it to the player, and the parameters are coming from the url line.
I see that you try to show the video on button click. The better way is to use a link that opens a new page that contains the video, or open a javascript window inside the page and show it, or just show a div block inside the page and show it. Look at this examples http://highslide.com/#examples on the "YouTube w/fade effect" to get an idea for how to open it in the same page and play it.
relative: how to work with videos in ASP.NET?
how to play sounds in asp.net using vb.net?
Upvotes: 5