title: ASP.NET and HTML5 Video play time
body: <p>Good afternoon stackoverflow!</p>
  
  <p>Currently I'm working on a handler to serve videos from a database to a control that will display it using HTML5. Using Response.OutputStream.Write does indeed work, however, the video player in both Firefox 4.0 and Chrome cannot seem to determine how long the video is. Firefox's counter just increases as the play time goes on, while Chrome shows a completely random time.</p>
  
  <p>Is there some header that I need to set in order for this to work? I have set the content-length to the number of bytes, which I think is the correct value. </p>
  
  <p><strong>HTML Markup</strong>
      </p>
  
  <pre><code>&lt;video controls="controls" poster="&lt;%= ImageURL %&gt;" width="&lt;%= Width %&gt;" height="&lt;%= Height %&gt;" preload="preload"&gt;
      &lt;source src="&lt;%= MP4URL %&gt;" type='video/mp4; codecs="avc1.42E01E,mp4a.40.2"'/&gt;
      &lt;source src="&lt;%= OggURL %&gt;" type='video/ogg; codecs="theora,vorbis"'/&gt;
      &lt;img alt="&lt;%= ImageAlt %&gt;" src="&lt;%= ImageURL %&gt;" width="&lt;%= Width %&gt;" height="&lt;%= Height %&gt;" title="No video playback capabilities, please download the video below" /&gt;
  &lt;/video&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Video Handler Code</strong></p>
  
  <pre><code>        // Snip -- Company specific DB code
  
          // Set the correct headers
          context.Response.AppendHeader("content-length", video.Length.ToString());
  
          // Set the content type
          switch (extensionType.ToLower())
          {
              case "ogv":
                  contentType = "video/ogg";
                  break;
  
              case "mp4":
                  contentType = "video/mp4";
                  break;
  
              default:
                  contentType = "";
                  break;
          }
          context.Response.ContentType = contentType;
          context.Response.Charset = String.Empty;
          context.Response.Buffer = false;
  
  
          // Write the video to the stream
          context.Response.OutputStream.Write(video, 0, video.Length);
  
          // Close the repsonse
          context.Response.Close();
          context.Response.End();
  </code></pre>
  
  <p>Any help on this would be greatly appreciated.</p>