Abstract: The following article demonstrates how to use the Video Web Helper ASP.NET MVC 3 RC 2, to add videos to our web pages.

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.

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.

Note: If you are doing ASP.NET MVC development, check out some ASP.NET MVC 3 RC articles over here too.

Open studio 2010 and create a new ASP.NET MVC 3 Web Application (Razor) project. The new MVC 3 dialog can be seen below:

Choose Razor as the view engine and click OK.

The next step is to download the Microsoft Web Helpers library through NuGet. Follow these steps to do this:

Step 1: Right click the website and choose Add Package Reference.

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-helpers option. Select that option and click Install.

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:

path – the path to the video file

width – the width of the video rendered in the web page

height - the height of the video rendered in the web page

play – value that determines if the video will play automatically

loop – value that determines if the video automatically starts upon ending

menu – value that determines if the context menu is visible

bgColor – the background colour of the helper

quality – the output video quality. Values include low, autolow, autohigh, medium, high, and best

scale – sets the size of the video. Values include exactfit, showall and noorder

windowMode – sets the placement of the video. Values include transparent, window and opaque

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:

path – the path to the video file

width – the width of the video rendered in the web page

height - the height of the video rendered in the web page

autoStart – value that determines how many times the video will play automatically

uiMode – value that determines which controls show up in the user interface. Values include invisible, none, mini, or full

stretchToFit – value that determines if video will stretch to fit the width and height settings

enableContextMenu – value that determines if a context menu appears when right-clicking on the video

mute – self explanatory

volume – self explanatory

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:

path – the path to the video file

width – the width of the video rendered in the web page

height - the height of the video rendered in the web page

bgColor – the background colour of the video

autoUpgrade – value that determines whether or not the control will upgrade to a newer version of Silverlight if available

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

This article has been editorially reviewed by Suprotim Agarwal.

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn. We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle). Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview. Click here to Explore the Table of Contents or Download Sample Chapters!