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?
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With