February 06, 2008
Silverlight and ASP.NETThe Media Control
The Media web control gives you a server-side abstraction over the MediaElement class from Silverlight. The obvious question is, "When should you use the MediaElement, and when should you prefer the server-side Media web control?" They both amount to the same thing -- after all, the server-side Media web control renders a MediaElement,s although it requires slightly more work on the server to do so. The primary advantage to using the Media web control is that you have the chance to set some of its properties using server-side code. For example, you could set the media URL based on information from a database and even extract it through data binding.
Here's an example of how you might define the Media control:
<asp:Media runat="server" ID="Media1" AutoPlay="true" MediaUrl="MyVideoFile.wmv" SilverlightBackColor="blue" MediaSkin="Professional" Height="240" Width="320" />
This creates a Silverlight control with a media player in it, as shown in Figure 1.
[Click image to view at full size]
Figure 1: The Silverlight media player
The media player attempts to access the MyViewFile.wmv file, and begins playing it immediately. In order to streamline the video playback experience, the media player downloads and buffers small chunks of video data as it plays. Best of all, the Silverlight media player works without requiring Windows Media Player. It's more lightweight and performant, and the user interface (playback buttons, skin, and so on) is more customizable.
To get the most out of Silverlight's media playing ability, you need to take a closer look at the properties provided by the Media control. Table 1 lists some of the most important.
Table 1: Properties of the Media Web Control
There are several more features of the Media control that aren't covered here:
You can also set various OnXxx properties (like OnClientMediaEnded and OnClientMediaFailed) to trigger a JavaScript function when a specific event happens in the media player. For information about these more advanced tasks, refer to http://quickstarts.asp.net/Futures/Silverlight/media.aspx.
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|