gpt4 book ai didi

asp.net-core-2.0 - 在asp.net core 2中流式传输视频文件

转载 作者:行者123 更新时间:2023-12-04 07:27:57 25 4
gpt4 key购买 nike

我想使用 asp.net core 在浏览器中播放视频

在html中我有

<video width="320" height="240" controls>
<source src="http://localhost:55193/api/VideoPlayer/Download" type="video/mp4">
Your browser does not support the video tag.
</video>

并在asp.net core 2中
    [HttpGet]
[Route("Download")]
public async Task<IActionResult> Download()
{
var path = @"d:\test\somemovie.mp4";
var memory = new MemoryStream();
using (var stream = new FileStream(@"d:\test\somemovie.mp4", FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 65536, FileOptions.Asynchronous | FileOptions.SequentialScan))
{
await stream.CopyToAsync(memory);
}
memory.Position = 0;
return File(memory, "application/octet-stream", Path.GetFileName(path));
}

此代码是否通过流播放文件(我的意思是逐块缓冲文件并播放)?

如果我想从用户设置播放器进度的任何位置播放文件,我该怎么做?

最佳答案

就用普通的return PhysicalFile这里:

public class HomeController : Controller
{
public IActionResult Download()
{
return PhysicalFile(@"d:\test\somemovie.mp4", "application/octet-stream");
}

因为它支持流式传输和恢复文件下载所需的范围 header :
enter image description here

还有 return File , FileStreamResultVirtualFileResult支持 partial range requests也。偶 static files middleware也支持。

关于asp.net-core-2.0 - 在asp.net core 2中流式传输视频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51338193/

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