Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Azure blob存储和ASP.NET Core 3流式播放视频_C#_Azure_Asp.net Core_Azure Storage Blobs - Fatal编程技术网

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;