您的位置:首页 > 其它

Add Videos On MVC Web Page- Web Helper

2011-10-29 16:33 323 查看
Source:http://www.dotnetcurry.com/(X(1)S(4eqxotqwohq03aerm3zqgj55))/ShowArticle.aspx?ID=622

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-helpersoption. 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:

[align=justify]path – the path to the video file [/align]

[align=justify]width – the width of the video rendered in the web page [/align]

[align=justify]height - the height of the video rendered in the web page [/align]

[align=justify]play – value that determines if the video will play automatically [/align]

[align=justify]loop – value that determines if the video automatically starts upon ending [/align]

[align=justify]menu – value that determines if the context menu is visible [/align]

[align=justify]bgColor – the background colour of the helper [/align]

[align=justify]quality – the output video quality. Values include low, autolow, autohigh, medium, high, and best [/align]

[align=justify]scale – sets the size of the video. Values include exactfit, showall and noorder [/align]

[align=justify]windowMode – sets the placement of the video. Values include transparent, window and opaque[/align]

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:

[align=justify]path – the path to the video file [/align]

[align=justify]width – the width of the video rendered in the web page [/align]

[align=justify]height - the height of the video rendered in the web page [/align]

[align=justify]autoStart – value that determines how many times the video will play automatically [/align]

[align=justify]uiMode – value that determines which controls show up in the user interface. Values include invisible, none, mini, or full [/align]

[align=justify]stretchToFit – value that determines if video will stretch to fit the width and height settings [/align]

[align=justify]enableContextMenu – value that determines if a context menu appears when right-clicking on the video [/align]

[align=justify]mute – self explanatory [/align]

[align=justify]volume – self explanatory[/align]

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐