简体   繁体   English

stream 视频 Blazor 组件 Web 服务器 Z240AA2CEC4B29C56F3BEE520ADC8Z

[英]stream video from AzureBlob in Blazor component Web Server c#

I am working on a feature where I want to stream video from azure blob.video files are already uploaded to azureBlob, I can use the blob URI but my blobs are compressed so I cant stream video directly from the Blob URI. I am working on a feature where I want to stream video from azure blob.video files are already uploaded to azureBlob, I can use the blob URI but my blobs are compressed so I cant stream video directly from the Blob URI. for that reason I fetch the blob from the azure storage, Decompressed it and got the actual memory stream of a video.出于这个原因,我从 azure 存储中获取 blob,对其进行解压缩并获得视频的实际 memory stream。 Now I want to play the video from that stream.现在我想播放来自 stream 的视频。 I researched out and find out that from JS it can be achieved.我研究了一下,发现从JS可以实现。 but I don't want to use js snippet to run this.但我不想使用 js 片段来运行它。 is there any balzor web component from which I can achieve this.是否有任何 balzor web 组件可以实现这一点。 I have also tried to used blazored.video library from Nuget but still I didn't find that much helpful.我也尝试过使用 Nuget 中的 blazored.video 库,但我仍然没有发现太多帮助。

@using Blazored.Video
@using Blazored.Video.Support


@if (File != null)
{
    <BlazoredVideo class="w-100"
                   style="max-width:800px;"
                   controls="controls">
        <source src="@File.FileUri" type="video/mp4" />
    </BlazoredVideo>
}

I have found a way to achieve this It simply requires me to create a web API that returns the content stream of my video.我找到了实现这一点的方法它只需要我创建一个 web API 来返回我的视频的内容 stream。

I follow this example to handle streaming in my Web API我按照这个例子在我的 Web API 中处理流式传输

Asynchronously Streaming Video with.Net Core API from Azure Blob Storage 使用.Net Core API 从 Azure Blob 存储异步流式传输视频

My work我的工作

Page.razor页.razor

<BlazoredVideo class="w-100"
               style="max-width:800px;"
               controls="controls">
    <source src="api/Blob/PlayVideo" type="video/mp4" />
</BlazoredVideo>

API Endpoint API 端点

 [HttpGet("api/Blob/PlayVideo")]
        [AllowAnonymous]
        public async Task<IActionResult> AnonymousPlayVideoAsync()
        {               
                var cloudBlob = await _azureBlobStorageService.RetrieveBlobiAsync("Test.mp4");
          
             var stream = new MemoryStream();
            await cloudBlob.DownloadToStreamAsync(stream);

            //.. Decompression of Stream comes here

            var result= new FileContentResult(stream.ToArray(), "video/mp4");
            result.EnableRangeProcessing = true;           
            return result;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM