Partial content in .NET Core MVC (for video/audio streaming)

前端 未结 2 1364
旧巷少年郎
旧巷少年郎 2020-12-31 06:09

I am trying to implement video and audio streaming on my website (to enable seeking in Chrome) and I recently found out that .NET Core 2.0 apparently provides a relatively s

2条回答
  •  我在风中等你
    2020-12-31 06:48

    There will be an enableRangeProcessing parameter added to the File method in version 2.1. For now, you need to set a switch. You can do this one of two ways:

    In runtimeconfig.json :

    {
      // Set the switch here to affect .NET Core apps
      "configProperties": {
        "Switch.Microsoft.AspNetCore.Mvc.EnableRangeProcessing": "true"
      }
    }
    

    or:

     //Enable 206 Partial Content responses to enable Video Seeking from 
     //api/videos/{id}/file,
     //as per, https://github.com/aspnet/Mvc/pull/6895#issuecomment-356477675.
     //Should be able to remove this switch and use the enableRangeProcessing 
     //overload of File once 
     // ASP.NET Core 2.1 released
    
       AppContext.SetSwitch("Switch.Microsoft.AspNetCore.Mvc.EnableRangeProcessing", 
       true);
    

    See ASP.NET Core GitHub Repo for details.

提交回复
热议问题