gpt4 book ai didi

jquery - 视频流显示在 Microsoft Edge 中不起作用

转载 作者:行者123 更新时间:2023-12-04 23:24:40 29 4
gpt4 key购买 nike

我是在 ASP.Net MVC 项目中使用视频流的新手。我有一个视频库网页应用,大部分视频都是.mp4格式。请在下面查看我的代码。

代码

public HttpResponseMessage Get(string filename)
{
var filePath = new FileStreameHelpers().GetFilePath(filename);
if (!File.Exists(filePath))
return new HttpResponseMessage(HttpStatusCode.NotFound);

var response = Request.CreateResponse();
response.Headers.AcceptRanges.Add("bytes");

var streamer = new FileStreameHelpers();
streamer.FileInfo = new FileInfo(filePath);
response.Content = new PushStreamContent(streamer.WriteToStream, new FileStreameHelpers().GetMimeType(Path.GetExtension(filePath)));

RangeHeaderValue rangeHeader = Request.Headers.Range;
if (rangeHeader != null)
{
long totalLength = streamer.FileInfo.Length;
var range = rangeHeader.Ranges.First();
streamer.Start = range.From ?? 0;
streamer.End = range.To ?? totalLength - 1;

response.Content.Headers.ContentLength = streamer.End - streamer.Start + 1;
response.Content.Headers.ContentRange = new ContentRangeHeaderValue(streamer.Start, streamer.End,
totalLength);
response.StatusCode = HttpStatusCode.PartialContent;
}
else
{
response.StatusCode = HttpStatusCode.OK;
}

return response;
}
public async Task WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
{
try
{
var buffer = new byte[6553600];
using (var video = FileInfo.OpenRead())
{
if (End == -1)
{
End = video.Length;
}
var position = Start;
var bytesLeft = End - Start + 1;
video.Position = Start;
while (position <= End)
{
var bytesRead = video.Read(buffer, 0, (int)Math.Min(bytesLeft, buffer.Length));
await outputStream.WriteAsync(buffer, 0, bytesRead);
position += bytesRead;
bytesLeft = End - position + 1;
}
}
}
catch (Exception ex)
{
// fail silently
Utilities.SaveException("FileStreameHelpers - WriteToStream", ex);
}
finally
{
outputStream.Close();
}
}

它在 Firefox 和 Chrome 中运行良好,但在 Microsoft Edge 浏览器中显示错误,如下所示。

HTML
<video width="320" height="240" controls>
<source src="/api/Media/Get?filename=SampleVideo_1280x720_1mb.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

远程主机关闭了连接。错误代码为 0x800703E3。

请指教。

最佳答案

实际上这是一个浏览器相关的问题。我更新了我的 MS Edge 浏览器。现在视频流正常工作。

关于jquery - 视频流显示在 Microsoft Edge 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53085661/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com