如何在 ASP.NET MVC HTML 音频播放器中播放 500Мb 大文件?

How to play large file 500Мb in ASP.NET MVC HTML audio player?

我尝试了这些方法来解决这个问题。

  1. Return 文件路径;

    [HttpGet]
    public ActionResult GetTrackById(Guid id)
    {
       string fileNameOnServer = GetFile(id);
       return  File(fileNameOnServer , Response.ContentType);
    }
    
  2. Return字节数组

    [HttpGet]
    public ActionResult GetTrackById(Guid id)
    {
       byte[] bufferToSend = GetFile(id);
       return  File(bufferToSend, Response.ContentType);
    }
    

    在这种情况下,我得到 OutOfMemoryException。

  3. Return 流

    [HttpGet]
    public ActionResult GetTrackById(Guid id)
    {
       Stream stream = GetFile(id);
       return  File(stream , Response.ContentType);
    }
    

那么问题来了,如何分段播放音频文件,并让音频播放器发送范围请求来播放和加载文件。我在 Google 上找不到任何有用的信息。

您是否尝试过异步生成响应流?这些链接可能会有帮助...

https://www.c-sharpcorner.com/article/asynchronous-videos-live-streaming-with-asp-net-web-apis-2-0/

http://www.tugberkugurlu.com/archive/efficiently-streaming-large-http-responses-with-httpclient