I am developing a website where people can access audio and video files. I have code for downloading files, which consists of two action methods, as shown below.
public ActionResult GetAudioFile(int id) { return GetFile(id, true); } public ActionResult GetVideoFile(int id) { return GetFile(id, false); } private ActionResult GetFile(int id, bool isAudio) {
Both of these work fine, and I can upload any type of file.
Now I want to add two types of Razor, one for listening to the audio file and one for watching the video. I did the following in audio form and it works great ...
<audio src='@Url.Action("GetAudioFile", "Search", new {ID = @Model.ID})' controls preload="auto"></audio>
Then I tried to do the same for watching the video ...
<video src='@Url.Action("GetVideoFile", "Search", new {ID = @Model.ID})' controls preload="auto" width="640" height="368"></video>
However, this gives a System.OutOfMemoryException exception when I try to run it. Videos averaged around 400-500 MB.
Then I tried to use the Response.TransmitFile method as follows:
Response.ContentType = "video/mp4"; Response.AddHeader("content-disposition", "attachment; filename=myvideo.mp4")); Response.TransmitFile(fileName); Response.End(); return null;
... but it does not work. In Chrome, I see the message βResource interpreted as a Document but transmitted with the MIME type of video / mp 4β in the console, and in FireFox I get the same message in the video control.
Does anyone know how I can fix this? Ideally, I would like to transfer the file so that it starts playing as soon as the first bytes reach the user, instead of waiting for them until the file is fully loaded.
I tried a couple of Javascript video players but was successful with them as well.
Update . I am wondering if this controller is not a problem, since I tried to point my web browser directly to the video file, and I got what looked like an audio player, but without a video panel, and nothing happens when I press the play button. Not sure if this helps.