将视频文件流式传输到idevice

时间:2013-04-02 03:45:20

标签: asp.net ios streaming

我是asp.net的新手 我尝试使用ashx流式传输mp4文件,它适用于桌面上的一些浏览器,但是idevices可以播放它。 我已经搜索了很多关于范围标题的解决方案,我试试solution先生Martin-Brennan,但它仍然不适合我:(,这是我的代码。抱歉我的英文,谢谢!

顺便说一下,我想问一下视频的重写网址,我的视频网址是http://mydomain/video/test.mp4是否有可能重写为http://mydomain/a23sdsf21ds/test.mp4,我无法用扩展名重写网址

//First, accept Range headers.
context.Response.AddHeader("Accept-Ranges", "bytes");
context.Response.ContentType = "video/mp4";
//Then, read all of the bytes from the file you are requesting.
var file_info = new System.IO.FileInfo(context.Server.MapPath("~/media/test.mp4"));
var bytearr = File.ReadAllBytes(file_info.FullName);

//Then, you will need to check for a range header, and then serve up a 206 Partial Content status code in your response.
var startbyte = 0;
if (!string.IsNullOrEmpty(context.Request.Headers["Range"]))
{
            var cs = new Char[] { '=', '-' };
            //Get the actual byte range from the range header string, and set the starting byte.
            var range = context.Request.Headers["Range"].Split(cs);
            startbyte = (int)Convert.ToInt64(range[1]);

            //Set the status code of the response to 206 (Partial Content) and add a content range header.
            context.Response.StatusCode = 206;
            context.Response.AddHeader("Content-Range", String.Format(" bytes {0}-{1}/{2}", startbyte, bytearr.Length - 1, bytearr.Length));
        }
  //Finally, write the video file to the output stream, starting from the specified byte position.
  context.Response.OutputStream.Write(bytearr, startbyte, bytearr.Length - startbyte);

0 个答案:

没有答案