Go to Visual Studio
File-> New-Project
File-> New-Project
The below screen gets displayed. Give any name of the application.
After clicking on ok , the below screen gets displayed:
Select Empty and select the check box MVC
Let us create a custom action result, Now i have created a Folder with the Name CustomResult inside that i have created a new class File as shown Below
Write the below code in the PlayVideo.cs File
public class PlayVideo:ActionResult
{
public override void ExecuteResult(ControllerContext context)
{
//The File Path
var videoFilePath = HostingEnvironment.MapPath("~/Videos/big_buck_bunny.mp4");
//The header information
context.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=Avent Anniversary.mp4");
var file = new FileInfo(videoFilePath);
//Check the file exist, it will be written into the response
if (file.Exists)
{
var stream = file.OpenRead();
var bytesinfile = new byte[stream.Length];
stream.Read(bytesinfile, 0, (int)file.Length);
context.HttpContext.Response.BinaryWrite(bytesinfile);
}
}
}
Controller . Create a new controller with the Name VideoController
public class VideoController : Controller
{
// GET: Video
public ActionResult Index()
{
return new PlayVideo();
}
}
Create a new Index
Now run the application , Now You can see the below output
Create another Contoller with the Name
public class PlayVideoLiveController : Controller
{
// GET: PlayVideoLive
public ActionResult Index()
{
return View();
}
}
Index.cs.html
<video width="320" height="240" controls autoplay="autoplay">
<source src="@Url.Action("Index","Video")" type="video/mp4">
</video>
Output:
Really nice blog post.provided a helpful information.I hope that you will post more updates like this
ReplyDeleteDot NET Online Training Hyderabad