我有一个处理程序,返回一个视频文件的视频标签的"源":
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.5ASP。净:4
框架:4.5.1
语言:Oxygene by Delphi Prism (Embarcadero)
iPhone和iPad可以使用相对目录