使用 MVC3 和 flowplayer,我有一个视频播放器,它设置为获取具有以下标记的视频文件:
<div id="video">
<div id="video-viewport">
<!-- The data-ratio is a decimal number represeting the height of the video in proportion to the width -->
<div class="flowplayer" data-swf="http://releases.flowplayer.org/5.1.1/flowplayer.swf"
data-ratio="0.417" data-engine="html5" data-keyboard="true" data-native_ipad_fullscreen="true"
data-volume="0.6">
<video>
<!-- By default Flowplayer attempts to use HTML5 video and if it's not
supported then Flash (9.0+) and MP4 is used. MP4 is enough for
complete browser support but providing WebM and/or OGG gives you
broader support for HTML5 video which is the preferred technology. -->
<!-- MP4 gives a complete cross browser support with the aid of Flash -->
<source type="video/mp4" src="@Url.Action("GetVideo", "Video", new { id = Model.WebMp4Video.Id })"/>
<!-- WEBM gives HTML5 video support for the latest Firefox, Chrome and Opera browser -->
<source type="video/webm" src="@Url.Action("GetVideo", "Video", new { id = Model.WebMVideo.Id })"/>
<!-- OGG gives HTML5 support for older versions of Firefox and Opera -->
<source type="video/ogv" src="@Url.Action("GetVideo", "Video", new { id = Model.OgvVideo.Id })"/>
</video>
</div>
</div>
</div> <!--/video-->
在控制器中,我有这个方法返回视频:
public ActionResult GetVideo(string id) {
...
var cd = new System.Net.Mime.ContentDisposition {
Inline = false
};
FileInfo info = new FileInfo(path);
Response.AppendHeader("Content-Disposition", cd.ToString());
return new RangeFilePathResult(MimeType, info.FullName, info.LastWriteTimeUtc, info.Length);
}
RangeFilePathResult一直是返回部分响应的救命稻草,这在 Firefox 和 IE 中一切正常,但在 Chrome 中我经常遇到错误:
“发送 http 标头后服务器无法设置状态”。
并且播放器本身崩溃,在页面上显示以下错误:
html5:视频未正确编码
我仍在尝试了解部分响应,但这可能是因为 RangeFileResult 为每个部分响应设置了状态代码 206?或者还有什么我在这里想念的吗?
编辑:如果我通过 RangeFileResult 代码进行调试并检查 Chrome 中的 Network 选项卡,我注意到一旦代码到达此行,对控制器方法的请求就会返回部分响应,状态为挂起:
context.HttpContext.Response.Flush();
这似乎有一个延迟,有时超过 10 秒,但是当这完成时,响应的状态变为 206。通常在播放视频时,状态再次变为取消,这是当
html5:视频未正确编码
消息出现在视频播放器上。
Edit2:我得到的回复如下(3个回复,第一个和第三个被取消,第二个有206状态:
要求
URL: http://localhost:64729/Video/GetVideo/24
Method: GET
Status Code: 206 Partial Content
请求标头
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:identity;q=1, *;q=0
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:.ASPXAUTH=BD5B9748E6985F5659B56289A5543C11CACBF1602AFFD5D4335453560988B870F2543269809401D13EE9F12EFBAC2D4CE0322B5F826871B9968B3D2986C01E35C536B28B5EC24E8E4F631D094B0DBEFF76DA84DA7CCC753E06C38C0FA36A858AC87548099BD23D4BE9B80434970A542489EC5E5F4543A9C98CA573F196DCBFE1B8CC18C10AE1AFEB0E4E899C6CA4DEFC59138E170954016DCB9C007FDC7C2B2950436E24AA5FF9C0888822626C9AE01C07A98F317A9499F0E9D5E61434F959E9;ASP.NET_SessionId=o112vzki5owvbptr4kudbdax
Host:localhost:64729
Range:bytes=0-
Referer:http://localhost:64729/Video/Index/3
User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17
响应标头
Cache-Control:private, s-maxage=0
Connection:Close
Content-Length:7362920
Content-Range:bytes 0-7362919/7362920
Content-Type:video/mp4
Date:Tue, 15 Jan 2013 12:55:24 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
要求
URL: http://localhost:64729/Video/GetVideo/24
Method: GET
Status Code: 206 Partial Content
请求标头
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:identity;q=1, *;q=0
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:.ASPXAUTH=BD5B9748E6985F5659B56289A5543C11CACBF1602AFFD5D4335453560988B870F2543269809401D13EE9F12EFBAC2D4CE0322B5F826871B9968B3D2986C01E35C536B28B5EC24E8E4F631D094B0DBEFF76DA84DA7CCC753E06C38C0FA36A858AC87548099BD23D4BE9B80434970A542489EC5E5F4543A9C98CA573F196DCBFE1B8CC18C10AE1AFEB0E4E899C6CA4DEFC59138E170954016DCB9C007FDC7C2B2950436E24AA5FF9C0888822626C9AE01C07A98F317A9499F0E9D5E61434F959E9;ASP.NET_SessionId=o112vzki5owvbptr4kudbdax
Host:localhost:64729
Range:bytes=7339303-
Referer:http://localhost:64729/Video/Index/3
User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17
响应标头
Cache-Control:private, s-maxage=0
Connection:Close
Content-Length:23617
Content-Range:bytes 7339303-7362919/7362920
Content-Type:video/mp4
Date:Tue, 15 Jan 2013 12:55:24 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
要求
URL: http://localhost:64729/Video/GetVideo/24
Method: GET
Status Code: 206 Partial Content
请求标头
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:identity;q=1, *;q=0
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:.ASPXAUTH=BD5B9748E6985F5659B56289A5543C11CACBF1602AFFD5D4335453560988B870F2543269809401D13EE9F12EFBAC2D4CE0322B5F826871B9968B3D2986C01E35C536B28B5EC24E8E4F631D094B0DBEFF76DA84DA7CCC753E06C38C0FA36A858AC87548099BD23D4BE9B80434970A542489EC5E5F4543A9C98CA573F196DCBFE1B8CC18C10AE1AFEB0E4E899C6CA4DEFC59138E170954016DCB9C007FDC7C2B2950436E24AA5FF9C0888822626C9AE01C07A98F317A9499F0E9D5E61434F959E9;ASP.NET_SessionId=o112vzki5owvbptr4kudbdax
Host:localhost:64729
Range:bytes=48-
Referer:http://localhost:64729/Video/Index/3
User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17
响应标头
Cache-Control:private, s-maxage=0
Connection:Close
Content-Length:7362872
Content-Range:bytes 48-7362919/7362920
Content-Type:video/mp4
Date:Tue, 15 Jan 2013 12:55:24 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0