【问题标题】:IHttpHandler ProcessRequest call twice only by SafariIHttpHandler ProcessRequest 仅由 Safari 调用两次
【发布时间】:2014-11-28 21:39:08
【问题描述】:

我有一个允许预览上传的媒体内容(图像、MP3、swf 文件和视频)的网络应用程序。所有上传的视频都使用 HTML5 视频标签正确编码和播放。

strHTML += '<video id="' + ObjectID + '" controls preload="auto" width="' + WIDTH + '" height="' + HEIGHT + '">' +
            '<source src="' + URL + '" type="video/mp4" />' +
            '</video>';

我有一个将上述 URL 映射到服务器上正确目录的源处理程序。

 public class SrcUrlHandler : IHttpHandler, IRequiresSessionState
 {
     public void ProcessRequest(HttpContext context)
     {
        //if previewing videos
        string filename = string.IsNullOrEmpty(spot.MEDIA_FILE) ? string.Empty : spot.MEDIA_FILE.Trim();
        string fileDir = tmpl.GetClientContentDirectory((int)clientId, ClientContentDirectory.Working);
        string fullName = fileDir + Path.DirectorySeparatorChar + "standardized_spid_" + spot.SPOT_ID + ".mp4";

        if (!File.Exists(fullName))
            return;

        FileInfo file = new FileInfo(fullName);
        context.Response.Clear();
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
        context.Response.ContentType = "video/mp4";
        context.Response.TransmitFile(file.FullName);
        context.ApplicationInstance.CompleteRequest();
     }
 }

这适用于 FF、IE、Windows 中的 Chorme 和 OSX 中的 Chrome。但是,这在 OSX 上的 Safari 上失败了。出于某种原因,Safari 会发出三个 http 请求。 ProcessRequest 被调用两次,并在第三次请求时失败。 (忽略下图中的第一行。)

第一个请求来自实际的浏览器。 来自用户代理 AppleCoreMedia 的第二个请求。 第三个来自 Quicktime。

为什么会这样?我发现的唯一类似问题是http://www.hanselman.com/blog/InternetExplorerAndTheMagicOfMicrosoftKBArticleQ293792.aspx,这不是很相关。预览适用于 safari 上的所有其他媒体类型(swf、png、jpg),它不会发出多个请求。最终的 302 响应代码没有意义,因为视频位置永远不会改变。提前谢谢你。

【问题讨论】:

    标签: asp.net safari http-headers video-streaming html5-video


    【解决方案1】:

    所以我终于解决了这个问题。 Safari 需要视频流才能使用 206 Partial Content 标头。我实现了在http://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/ 找到的代码,一切正常!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 2016-02-11
      • 1970-01-01
      相关资源
      最近更新 更多