title: Stream Video with ASP.NET
body: <p>Is there a good way to stream video through asp.net to a normal webpage and mobile? I've tried the following but it doesn't work in my Sony Ericsson K810i. When I try it in my browser, I can see the clip (don't know if it's streaming though).</p>
  
  <p>html: </p>
  
  <pre><code>&lt;object type="video/3gpp" 
          data="handlers/FileHandler.ashx" 
          id="player" 
          width="176" 
          height="148" 
          autoplay="true"&gt;&lt;/object&gt;
  </code></pre>
  
  <p>FileHandler.ashx (<a href="https://stackoverflow.com/questions/608480/best-way-to-stream-files-in-asp-net">Best way to stream files in ASP.NET</a>): </p>
  
  <pre><code>public void ProcessRequest (HttpContext context) {
  
      string path = "~/files/do.3gp";
  
      string localPath = context.Server.MapPath(path);
  
      if (!File.Exists(localPath))
      {
          return;
      }
  
      // get info about contenttype etc 
      FileInfo fileInfo = new FileInfo(localPath);
      int len = (int)fileInfo.Length;
      context.Response.AppendHeader("content-length", len.ToString());
      context.Response.ContentType = FileHelper.GetMimeType(fileInfo.Name); // returns video/3gpp
  
      // stream file
      byte[] buffer = new byte[1 &lt;&lt; 16]; // 64kb
      int bytesRead = 0;
      using(var file = File.Open(localPath, FileMode.Open))
      {
         while((bytesRead = file.Read(buffer, 0, buffer.Length)) != 0)
         {
              context.Response.OutputStream.Write(buffer, 0, bytesRead);
         }
      }
  
      // finish
      context.Response.Flush();
      context.Response.Close();
      context.Response.End();
  
  }
  </code></pre>