【发布时间】:2013-07-30 06:40:59
【问题描述】:
因此,由于内容与我的服务器应用程序的虚拟目录位于不同的驱动器上,我不得不实现文件获取服务。
我能够获取文件大小。然后我想设置内容标题,以便浏览器知道总大小,从而知道如何按比例搜索栏。
这里我设置了总大小标题:
string bytes = Convert.ToString( fInfo.Length );
Response.AddHeader("Content-Length", bytes );
Response.AddHeader("Content-Range", "bytes 0-" + bytes + "/" + bytes);
导致:
Content-Length: 1389363
Content-Type: video/ogg
Content-Range: bytes 0-1389363/1389364
我下载了生成的文件并确认字节匹配。在 Firefox 中运行良好,在 chrome 中都很古怪。 在chrome中它播放到最后,但不移动搜索栏,然后在到达结束时在当前时间显示负无穷大。另外我根本无法清理视频,大概是因为它的持续时间无效。
直接在chrome中播放同一个文件可以正常工作,所以也许是chrome希望firefox不给出s#%t的一些内容标题?
有什么想法吗?长度单位错误?内置服务器端 g-zip 编码干扰?
我正在使用标准视频对象:
<video class="videoplayer" controls="" autoplay="autoplay" tabindex="0">
<source type="video/ogg" src="http://vb_html.dev/GetFile.aspx?filename=c:/_assets/4c2c09c2-f2ff-e011-a992-009056af18ff/softsignage/softsignage-00000000600.ogv"></source>
Your browser does not support the video tag.
</video>
更多参考这是我传递文件数据的方式:
FileStream mystream = new FileStream(anyFilePath, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[4096];
using (BinaryReader reader = new BinaryReader(mystream))
{
while (true)
{
int bytesRead = mystream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0) break;
Response.OutputStream.Write(buffer, 0, bytesRead);
}
}
【问题讨论】:
-
看来我应该使用 Response.WriteFile() 但所有解决方案似乎都非常复杂,只是为了处理特定范围的请求。
标签: c# google-chrome html5-video seek