views:

23

answers:

0

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).

html:

<object type="video/3gpp" 
        data="handlers/FileHandler.ashx" 
        id="player" 
        width="176" 
        height="148" 
        autoplay="true"></object>

FileHandler.ashx (http://stackoverflow.com/questions/608480/best-way-to-stream-files-in-asp-net):

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 << 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();

}