0

I have a handler that returns a video file the "source" of a video tag:

    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;

Client code is

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

This code works fine on Chrome, Firefox and IE.
But in Safari by iPhone or iPad don't work and video don't load.

IIS: 7.5
ASP.NET: 4
Framework: 4.5.1
Language: Oxygene by Delphi Prism (Embarcadero)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Anibal Díaz
  • 111
  • 7

1 Answers1

0

For iPhone and iPad you can use relative directories.