Source:
ASP.NET MVC 3 RC 2 contains a full suite of web helpers that Microsoft have made available through the Microsoft Web Helpers library. One web helper that makes the process of creating rich user interfaces easier is the Video web helper. As the name suggests, this helper renders either a Windows Media, Flash or Silverlight video to the user, which is today’s world makes sense. This code also works in WebMatrix Beta 3 if you're using it.mvc
Before moving on, you need to download ASP.NET MVC 3 RC. Click here to download and install them using the Microsoft Web Platform Installer.app
Note: If you are doing ASP.NET MVC development, check out some ASP.NET MVC 3 RC articles over here too.ide
Open studio 2010 and create a new ASP.NET MVC 3 Web Application (Razor) project. The new MVC 3 dialog can be seen below:oop
Choose Razor as the view engine and click OK.ui
The next step is to download the Microsoft Web Helpers library through NuGet. Follow these steps to do this:this
Step 1: Right click the website and choose Add Package Reference.spa
Step 2: The Add Package Reference dialog will open. Search for Microsoft in the search box in the top right corner. Upon completion you'll see microsoft-web-helpersoption. Select that option and click Install.code
Step 3: Click 'Close' to return to the project
Check the references and you'll see that the library has been added to the project.
Now it's time to start coding! The web helper I’m focusing on today is the Video web helper. This web helper renders video to the end user. The videos that can be rendered are Windows Media, Flash and Silverlight.
Flash Videos
To play flash videos, you use the Video.Flash web helper. The only parameter that is mandatory is path. This can be a local file, or as in this example, a link to a Youtube video. All other parameters are optional.
The list below outlines the optional parameters:orm
When using windowMode, the outcome of setting the value to window will be the video file will open in a new window. Opaque will hide everything behind the video on the page. Transparent lets the background of the page show through the video, assuming any part of the video is transparent.
When using scale, showall makes the entire video visible while maintaining the original aspect ratio. Noorder scales the video while maintaining the original aspect ratio. Exactfit makes the entire video visible without preserving the original aspect ratio.
Windows Media Videos
To play WMV videos, you use the Video.MediaPlayer web helper. The only parameter that is mandatory is path. This can be a local file or a remote file.
The list below outlines the optional parameters:
When using uiMode, if you don't specify a parameter, the video will be displayed with the status window, seek bar, control buttons, and volume controls in addition to the video window.
Silverlight Videos
To play Silverlight videos, you use the Video.Silverlight web helper. The only parameter that is mandatory is path.
The list below outlines the optional parameters:
So with the Video web helper, adding video to your web pages just got easier.
The entire source code of this article can be downloaded over here