Answer the question
In order to leave comments, you need to log in
How to broadcast video with rewind capability in Asp.net mvc?
Hello, I'm learning to display a video on the site from a file. If you take the whole file and transfer it to the page, it works, the video is displayed, but I would like to deal with the following question: how to display the video not in its entirety, but, for example, from the middle? this may be needed, for example, if the video lasts 2 hours, and so that immediately after opening the page, the user can rewind the video to 01 hour 45 minutes and not wait for the file to fully download.
I saw this on YouTube. When you rewind - prev. the video request is canceled, and a new video request is created not from the beginning, but from the right minute.
With the help of trace. In the code, I tried to just jump 2500000 bytes forward (the video is 5MB in total), but the video is not displayed.
Video format: mp4
public override void ExecuteResult(ControllerContext context)
{
var strVideoFilePath = HostingEnvironment.MapPath("~/Content/big_buck_bunny.mp4");
context.HttpContext.Response.ContentType = "video/mp4";
context.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=Test2.mp4");
var objFile = new FileInfo(strVideoFilePath);
var stream = objFile.OpenRead();
int fakeLen = (int)stream.Length - 2500000;
var objBytes = new byte[fakeLen];
stream.Seek(2500000, SeekOrigin.Begin);
stream.Read(objBytes, 0, fakeLen);
context.HttpContext.Response.BinaryWrite(objBytes);
}
}
Answer the question
In order to leave comments, you need to log in
The video file must be sent from the server in its entirety. It cannot be cut like a regular array of bytes - this violates the format, and it will be impossible to play the video.
Instead, use the player's own API on the client side - when the page loads, execute a script that will tell the player to rewind to a certain point. If the player (and your server) supports uploading files from an arbitrary location (and not from the very beginning), then it should work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question