Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC4 Media Source Url for HTML5 Video

In my ASP.NET MVC 4, I want to stream video by using the HTML5 <video>. The video is stored at this location D:\movie\test.mp4.

How can I put this location as source to the <video> tag? I tried:

<source src="@Url.Content(@"D:\movie\test.mp4")" type="video/mp4" />

but not working. If I add the files into my project, and do it like this, <source src="@Url.Content("~/Script/test.mp4")" type="video/mp4" /> it will work.

What is the correct way of linking the source to the local file without having to put it in the project?

Also, should the media files be served in the IIS? What is the best practice for this, supposed that the location of the media is pulled of a table in a database?

like image 306
Haikal Nashuha Avatar asked Mar 24 '23 10:03

Haikal Nashuha


1 Answers

What is the correct way of linking the source to the local file without having to put it in the project?

There's no way to access arbitrary files on the server from the client. Just imagine the huge security vulnerability that would create if it was possible.

You can only access files that are part of the web application. If you absolutely need to access some arbitrary files, then you will need to write a controller action that will stream the file to the client:

public ActionResult Video()
{
    return File(@"D:\movie\test.mp4", "video/mp4");
}

and then point the source tag to this action:

<source src="@Url.Action("Video")" type="video/mp4" />
like image 139
Darin Dimitrov Avatar answered Apr 06 '23 17:04

Darin Dimitrov