C# 从Azure blob存储和ASP.NET Core 3流式播放视频
我正在使用最新和推荐的C# 从Azure blob存储和ASP.NET Core 3流式播放视频,c#,azure,asp.net-core,azure-storage-blobs,C#,Azure,Asp.net Core,Azure Storage Blobs,我正在使用最新和推荐的Azure.Storage.Blobs软件包。我将视频文件作为块上传,效果很好。现在的问题是将视频返回到web客户端,即videojs。播放机正在使用范围请求 我的端点: [HttpGet] [Route("video/{id}")] [AllowAnonymous] public async Task<IActionResult> GetVideoStreamAsync(string id) { var stream = await GetVideoFi
Azure.Storage.Blobs
软件包。我将视频文件作为块上传,效果很好。现在的问题是将视频返回到web客户端,即videojs
。播放机正在使用范围
请求
我的端点:
[HttpGet]
[Route("video/{id}")]
[AllowAnonymous]
public async Task<IActionResult> GetVideoStreamAsync(string id)
{
var stream = await GetVideoFile(id);
return File(stream, "video/mp4", true); // true is for enableRangeProcessing
}
视频下载和流媒体播放得很好。但它下载整个视频,根本不考虑范围。我还尝试了DownloadTo(HttpRange)
但浏览器中不会显示任何内容。实现这一点的最佳方法是什么?请在返回之前将内存流的位置重置为0
:
var ms = new MemoryStream();
// parse range header...
var range = new HttpRange(from, to);
BlobDownloadInfo info = await blobClient.DownloadAsync(range);
await info.Content.CopyToAsync(ms);
ms.Position = 0;//ms is positioned at the end of the stream so we need to reset that.
return ms;
我相信仅仅使用Azure Blob是不可能实现的。更多信息请点击此处:
但总而言之,您可以使用提供搜索开始/结束位置的CDN:
另一种可能是使用支持流化的Azure媒体服务。你的方法实际上是一种渐进式下载,这与你的想法不完全相同,你可能会花很多时间在网络上。(假设您对同一文件有多个访问权限)嗯,没有。。仍然没有视频。你能编辑你的问题并包括前端代码吗?我想模拟一下。
var ms = new MemoryStream();
// parse range header...
var range = new HttpRange(from, to);
BlobDownloadInfo info = await blobClient.DownloadAsync(range);
await info.Content.CopyToAsync(ms);
return ms;
var ms = new MemoryStream();
// parse range header...
var range = new HttpRange(from, to);
BlobDownloadInfo info = await blobClient.DownloadAsync(range);
await info.Content.CopyToAsync(ms);
ms.Position = 0;//ms is positioned at the end of the stream so we need to reset that.
return ms;