Hi, i'm making an app for my home server in asp.net core. I want to make videos available on the local harddrive to be used for a client(mobile app) to stream to a chromecast.
Making the app is not the problem, but making videos available on a url to be used is. I don't know how serving large files works in asp.net core. If I do this I can play it in the browser if it supports one of three video formats:
//location of videos in app string pathToVideos = _env.ContentRootPath + "\\Filmer\\"; public IActionResult Video(string videoFileName) { var path = Path.Combine(pathToVideos, videoFileName); return File(System.IO.File.OpenRead(path), "video/mp4"); }
This works using the html5 video element in the browser but i can't jump back and forth in the video, only play it from the start. What are the drawbacks of this and what is the difference of streaming to bytes and buffers etc like I suspect is the proper way to do it? I've only seen old examples. Only the class PushStreamContent is not in .net core. This is for old asp.net.
I also tried to make the video available as I would with any other normal files like this:
public IActionResult File(string video) { if (String.IsNullOrEmpty(video)) { return NotFound(); } return PhysicalFile(Path.Combine(_env.ContentRootPath, "Filmer", video), "video/mp4"); }
Then I can stream the video creating a stream with HttpClient and serve it as a FileStreamResult(): The url is the location of the file served by the File method(http://serveradress/File/sample.mp4)
[HttpGet("{name}")] public async Task<FileStreamResult> Get(string url) { HttpClient _client = new HttpClient(); var stream = await _client.GetStreamAsync(url); return new FileStreamResult(stream, "video/mp4"); }
It seems to work exactly the same as my first attemt, but I need to close the client somehow.
Any thoughts on how to do this?