What is the correct way to serve .m3u8 files in C# using ASP.NET Core 6.0? I tried for the longest time to write up something in one of the controller files, but couldn't get anything to work.
I finally settled on this approach in the program.cs file of the project, which does give you the file if you paste the url:
app.MapGet("/live.m3u8", () =>
{
string path = @"/data/videos/live/camera/live.m3u8";
var filestream = System.IO.File.OpenRead(path);
return Results.File(filestream, contentType: "application/x-mpegURL", fileDownloadName: "live.m3u8", enableRangeProcessing: true);
});
However, when I get to the Angular side of things, I can't get the feed to display at all.
<video width=600 height=300 controls autoplay>
<source
src="http://localhost:9900/live.m3u8"
type="application/x-mpegURL">
</video>
When I check the network tab, there are no calls being made to http://localhost:9900/live.m3u8
.
I think the biggest problem is that I have no idea how to setup a livestream with C# and Angular. I've been research for days and following tutorials but most stuff I find is over 10 years old and doesn't work anymore or isn't specific to C# and/or Angular.
Keep in mind the code above is not the only code I've tried, it's just the closest I've gotten to something that works (most of my other code would just throw 500 errors or give a 200 status code with no data attached).
I can't tell which part I'm doing wrong: the backend in C#, the frontend in Angular, or both.