How to stream video content in asp.net?

Posted by Kon on Stack Overflow See other posts from Stack Overflow or by Kon
Published on 2010-04-22T01:26:43Z Indexed on 2010/04/22 1:33 UTC
Read the original article Hit count: 325

Filed under:
|
|
|
|

Hi, I have the following code which downloads video content:

WebRequest wreq = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse())
using (Stream mystream = wresp.GetResponseStream())
{
  using (BinaryReader reader = new BinaryReader(mystream))
  {
    int length = Convert.ToInt32(wresp.ContentLength);
    byte[] buffer = new byte[length];
    buffer = reader.ReadBytes(length);

    Response.Clear();
    Response.Buffer = false;
    Response.ContentType = "video/mp4";
    //Response.BinaryWrite(buffer);
    Response.OutputStream.Write(buffer, 0, buffer.Length);
    Response.End();
  }
}

But the problem is that the whole file downloads before being played. How can I make it stream and play as it's still downloading? Or is this up to the client/receiver application to manage?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET