Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#通过http传输到iphone_C#_Iphone_Video Streaming - Fatal编程技术网

c#通过http传输到iphone

c#通过http传输到iphone,c#,iphone,video-streaming,C#,Iphone,Video Streaming,我正在尝试通过http将视频流传输到iphone,而无需使用.net服务器。 经过一些测试,我发现如果你只是上传与iphone兼容的视频到你的服务器上,iis7工作正常,iphone在很短的缓冲时间后开始播放视频,并继续在后台下载 我的问题是,我不能用.net来做这件事。我试过了 public static void SmallFile(string filename, string filepath, string contentType) { try {

我正在尝试通过http将视频流传输到iphone,而无需使用.net服务器。 经过一些测试,我发现如果你只是上传与iphone兼容的视频到你的服务器上,iis7工作正常,iphone在很短的缓冲时间后开始播放视频,并继续在后台下载

我的问题是,我不能用.net来做这件事。我试过了

    public static void SmallFile(string filename, string filepath, string contentType)
{
    try
    {
        FileStream MyFileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
        long FileSize;
        FileSize = MyFileStream.Length;
        byte[] Buffer = new byte[(int)FileSize];
        MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);
        MyFileStream.Close();
        HttpContext.Current.Response.ContentType = contentType;
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
        HttpContext.Current.Response.BinaryWrite(Buffer);

    }
    catch
    {
        HttpContext.Current.Response.ContentType = "text/html";
        HttpContext.Current.Response.Write("Downloading Error! " + filename + " not found!");
    }
    HttpContext.Current.Response.End();
}
或与

public static void ResumableFile(string filename, string fullpath, string contentType)
{
    try
    {
        FileStream myFile = new FileStream(fullpath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        BinaryReader br = new BinaryReader(myFile);
        try
        {
            HttpContext.Current.Response.AddHeader("Accept-Ranges", "bytes");
            HttpContext.Current.Response.Buffer = false;
            long fileLength = myFile.Length;
            long startBytes = 0;

            //int pack = 10240; //10K bytes
            int pack = 1048576; //1024K bytes
            if (HttpContext.Current.Request.Headers["Range"] != null)
            {
                HttpContext.Current.Response.StatusCode = 206;
                string[] range = HttpContext.Current.Request.Headers["Range"].Split(new char[] { '=', '-' });
                startBytes = Convert.ToInt64(range[1]);
            }
            HttpContext.Current.Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
            if (startBytes != 0)
            {
                HttpContext.Current.Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength));
            }
            HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive");
            HttpContext.Current.Response.ContentType = contentType;
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));

            br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
            int maxCount = (int)Math.Floor((double)((fileLength - startBytes) / pack)) + 1;

            for (int i = 0; i < maxCount; i++)
            {
                if (HttpContext.Current.Response.IsClientConnected)
                {
                    HttpContext.Current.Response.BinaryWrite(br.ReadBytes(pack));
                    }
                else
                {
                    i = maxCount;
                }
            }
        }
        catch
        {
            HttpContext.Current.Response.ContentType = "text/html";
            HttpContext.Current.Response.Write("Downloading Error! " + filename + " not found!");
        }
        finally
        {
            br.Close();
            myFile.Close();
        }
    }
    catch
    {
        HttpContext.Current.Response.ContentType = "text/html";
        HttpContext.Current.Response.Write("Downloading Error!" + filename + " not found!");
    }
}
部分,所以它不会触发完全下载,但结果是一样的

我已经检查了来自服务器的响应,当我直接下载文件时,并没有来自服务器的不同/额外的头

我想知道的是,当我直接下载视频文件时,是什么使iphone能够缓冲并开始播放视频,我如何用.net实现它

如果你想知道我为什么不使用iis,由于带宽限制,我需要设置一些水蛭保护

有人有经验吗

更新

这是来自iis的第一个请求和响应

GET /test.mp4 HTTP/1.1
Host: 192.168.2.200
User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; tr-tr) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16
Cache-Control: max-age=0
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: tr-tr
Accept-Encoding: gzip, deflate
Connection: keep-alive


HTTP/1.1 200 OK
Content-Type: video/mp4
Last-Modified: Wed, 23 Dec 2009 20:12:57 GMT
Accept-Ranges: bytes
ETag: "e6ad9151c84ca1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 23 Dec 2009 21:07:19 GMT
Content-Length: 2301438
和第二次请求和响应

GET /test.mp4 HTTP/1.1
Host: 192.168.2.200
Range: bytes=0-2269183
Connection: close
User-Agent: Apple iPhone OS v3.1.2 CoreMedia v1.0.0.7D11
Accept: */*
Accept-Encoding: identity



HTTP/1.1 206 Partial Content
Content-Type: video/mp4
Last-Modified: Wed, 23 Dec 2009 20:12:57 GMT
Accept-Ranges: bytes
ETag: "e6ad9151c84ca1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 23 Dec 2009 21:11:33 GMT
Connection: close
Content-Length: 2269184
Content-Range: bytes 0-2269183/2301438
据我所知,iphone在第二次请求时会请求不同的字节,以此类推。
是否有人让c#将这些字节范围发送到客户端?

我会执行某种消息嗅探

基本上,我会设置一些可以将视频流传输到iPhone的东西(比如TVersity),然后设置一些东西来拦截TVersity和iPhone之间的流量,以便您可以检查HTTP请求和响应

以下是一篇关于如何建立TVersity的博客:


相对url“/iPhone”是您想要嗅探流量的url。它应该能为将视频下载到iPhone上的正确信息交换模式提供一些帮助。

我会进行一些信息嗅探

基本上,我会设置一些可以将视频流传输到iPhone的东西(比如TVersity),然后设置一些东西来拦截TVersity和iPhone之间的流量,以便您可以检查HTTP请求和响应

以下是一篇关于如何建立TVersity的博客:


相对url“/iPhone”是您想要嗅探流量的url。它应该能为将视频下载到iPhone上的正确信息交换模式提供一些帮助。

我想我在

找到了我的解决方案我想我在

找到了我的解决方案试试这个

或者我第一次回复中的链接有源代码

试试这个


或者我的第一个回复中的链接有源代码

@nLL当设置内容处置标题时,如果服务器说未正确配置,您能否从服务器显示更多信息?错误来自iphone。无论内容配置设置与否,这种情况都会发生。我只是在使用iis进行简单下载/升级下载之后才会发生。http流不是我想要做的。分割文件需要相当多的工作etc@nLL当设置内容处置标题时,服务器显示未正确配置时,您是否可以显示来自服务器的更多信息?错误来自iphone。无论内容配置设置与否,这种情况都会发生。我只是在使用iis进行简单下载/升级下载之后才会发生。http流不是我想要做的。它需要相当多的工作来分割文件等
GET /test.mp4 HTTP/1.1
Host: 192.168.2.200
Range: bytes=0-2269183
Connection: close
User-Agent: Apple iPhone OS v3.1.2 CoreMedia v1.0.0.7D11
Accept: */*
Accept-Encoding: identity



HTTP/1.1 206 Partial Content
Content-Type: video/mp4
Last-Modified: Wed, 23 Dec 2009 20:12:57 GMT
Accept-Ranges: bytes
ETag: "e6ad9151c84ca1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 23 Dec 2009 21:11:33 GMT
Connection: close
Content-Length: 2269184
Content-Range: bytes 0-2269183/2301438