ASP. net mvc program to play H.264 videos,

Source: Internet
Author: User

ASP. net mvc program to play H.264 videos,

Before this article, Insus. NET whether in ASP. NET or ASP. net mvc to achieve a lot of video playback, you can refer to this link: http://www.cnblogs.com/insus/category/465053.html.

This time, Insus. NET wants to play a video in H.264 format in ASP. net mvc, such as MP4 or MOV. The following two types of video files are presented respectively.

Create a Result class:

 

The core part above is to convert the file to binary output. Of course, there is another way to convert to binary. You can refer:

 

Hdotaskresult class code:

Public class hdotaskresult: ActionResult {public string FilePhysicalPath {private get; set;} public override void ExecuteResult (ControllerContext context) {var file = new FileInfo (FilePhysicalPath); if (file. exists) {context. httpContext. response. addHeader ("Content-Disposition", "attachment; filename =" + file. name); // var stream = file. openRead (); // var bytes = new byte [stream. length]; // stream. read (bytes, 0, (int) file. length); // context. httpContext. response. binaryWrite (bytes); FileStream fs = new FileStream (FilePhysicalPath, FileMode. open, FileAccess. read); BinaryReader br = new BinaryReader (fs); Byte [] bytes = br. readBytes (Int32) fs. length); br. close (); fs. close (); context. httpContext. response. outputStream. write (bytes, 0, bytes. length );}}}View Code



Prepare an mov video for Demonstration:

 

OK. I need to create a controller in the MVC program. Today is July, and a July15Controller is created. All the exercises in this month are stored in this controller.



In the controller, we have created two Action operations, one for the view and the other for the display video.

Next, create the View:

 

To see the effect:

 


Next, let's try out the video "pai.mp4:

 

The Controller slightly modifies the path:

 

The view does not need to be modified. Run the browser to see the effect:


Because the video is large, the loading time is longer.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.