0

I am working on .NET Core 5 MVC. This is probably a xy problem.

I am trying to stream a .m3u8 file to a browser video player (video.js). The video player reads the .m3u8 and will try to request a .ts file for the video segments of it and will stream them in order according to the .m3u8 file.

I have a controller called Video. In this controller, I have an action called 'GetStream' which returns the .m3u8 file on the computer.

This is the request:

Request URL: https://localhost:44333/Video/GetStream Request 
Method: GET Status Code: 200  Remote Address: [::1]:44333 Referrer 
Policy: strict-origin-when-cross-origin

The response:

Accept-Ranges: bytes
Content-Length: 172
Content-Type: application/octet-stream
Date: Fri, 23 Jul 2021 18:21:58 GMT
Last-Modified: Fri, 23 Jul 2021 17:50:41 GMT
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET

That is response is correct. The issue is that when the video player tries to get the .ts files from the information in the .m3u8 GetStream file, it sends this request:

Request URL: https://localhost:44333/Video/2021-07-23_12-50-350.ts
Request Method: GET
Status Code: 302 
Remote Address: [::1]:44333
Referrer Policy: strict-origin-when-cross-origin

And of course, that returns a 404 error since there is no action that would return that file.

==============================================================

Controller:

[HttpGet]
public FileResult GetStream()
{
    return PhysicalFile(@"C:...\wwwroot\vods\2021-07-23_12-50-35.m3u8", "application/octet-stream", enableRangeProcessing: true);
}

Am I overlooking something?

dimitar.bogdanov
  • 387
  • 2
  • 10
Haley Mueller
  • 487
  • 4
  • 16

1 Answers1

1

I had to do some route changes on the actions to redirect it to the right spot.

    [HttpGet("[controller]/GetStream")]
    public FileResult GetStream()
    {
        return PhysicalFile(@"C:\..\wwwroot\vods\2021-07-23_13-52-52.m3u8", "application/octet-stream", enableRangeProcessing: true);
    }

    [HttpGet("[controller]/{tsFileName}")]
    public ActionResult GetTsFile(string tsFileName)
    {
        if (string.IsNullOrEmpty(tsFileName))
            return new EmptyResult();

        return PhysicalFile(@"C:\..\wwwroot\vods\" + tsFileName, "application/octet-stream", enableRangeProcessing: true);
    }

Thanks to @abdusco for pointing me in the right direction

Haley Mueller
  • 487
  • 4
  • 16