【问题标题】:Send video streaming to web browser on iOS with handler (.ashx)使用处理程序 (.ashx) 将视频流发送到 iOS 上的 Web 浏览器
【发布时间】:2015-11-14 06:26:56
【问题描述】:

我有一个处理程序,它返回一个视频标签的“源”视频文件:

    file_info := new System.IO.FileInfo(_Fichero._RutaPrivada);
    bytearr := File.ReadAllBytes(file_info.FullName);
    startbyte := 0;
    endbyte := bytearr.Length;

    //context.Response.Buffer := false;
    context.Response.AddHeader("Accept-Ranges", "bytes");
    context.Response.AddHeader("Content-Type", MimeMapping.GetMimeMapping(file_info.Name).Replace('quicktime', 'mp4'));
    context.Response.AddHeader("Last-Modified", _Fichero._FechaAlta.ToString('R'));
    MD5Enc := new MD5CryptoServiceProvider();
    hash := BitConverter.ToString(MD5Enc.ComputeHash(bytearr)).Replace('-', String.&Empty);
    ETAG := new EntityTagHeaderValue('"' + hash + '"');
    context.Response.AddHeader("ETag", ETAG.Tag);

    if context.Request.Headers["Range"] <> nil then
    begin
      chars := new array of Char(2);
      chars[0] := '=';
      chars[1] := '-';
      range := context.Request.Headers["Range"].Split (chars);

      startbyte := Integer(Convert.ToInt64(range[1]));
      if (range[2] <> nil) and (not range[2].IsEmpty) then
        endbyte := Integer(Convert.ToInt64(range[2]));


      //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, endbyte - 1, bytearr.Length));
    end;

    context.Response.AddHeader("Content-Length", (endbyte - startbyte).ToString);   
    //Finally, write the video file to the output stream, starting from the specified byte position.
    context.Response.OutputStream.Write(bytearr, startbyte, endbyte - startbyte);
    context.Response.OutputStream.Flush;

客户端代码是

<video id="video_6546" class="video-js vjs-default-skin" data-setup="{}" preload="auto" controls="controls">    
    <source type="video/mp4" src="/Handlers/PreviewByFile.ashx?PECO=oqkyuz2gwmx4xnick0tfem45"></source>
</video>

此代码在 Chrome、Firefox 和 IE 上运行良好。
但在 iPhone 或 iPad 上的 Safari 中无法正常工作,也无法加载视频。

IIS:7.5
ASP.NET:4
框架:4.5.1
语言:Oxygene by Delphi Prism (Embarcadero)

【问题讨论】:

  • 解决这个问题需要使用.NET技术,而不是JAVA。
  • 好的,感谢您澄清这一点。您可能需要使用答案旁边的绿色复选标记。

标签: ios video stream ashx handlers


【解决方案1】:

对于 iPhone 和 iPad,您可以使用相对目录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-13
    • 2012-02-17
    • 1970-01-01
    • 2013-11-17
    • 2018-04-06
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    相关资源
    最近更新 更多