Printer Friendly Version      Send     
Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
MediaElement Class
Other versions are also available for the following:
.NET Framework Class Library for Silverlight
MediaElement Class
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Represents an object that contains audio, video, or both.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

Visual Basic (Declaration)
Public NotInheritable Class MediaElement _
    Inherits FrameworkElement
Visual Basic (Usage)
Dim instance As MediaElement
C#
public sealed class MediaElement : FrameworkElement
Visual C++
public ref class MediaElement sealed : public FrameworkElement
JScript
public final class MediaElement extends FrameworkElement
XAML Object Element Usage
<MediaElement .../>

A MediaElement is basically a rectangular region that can display video on its surface, or play audio (in which case there is no video displayed, but the MediaElement still acts as a player object with appropriate APIs). Because it is a UIElement, a MediaElement supports input operations such as mouse and keyboard events, and can capture focus or the mouse. You can specify the height and width of the video display surface using the properties Height and Width. However, for best performance, avoid explicitly setting the width and height of a MediaElement. Instead, leave the values unset. Once you specify a source, the media will display at its natural size, and layout will recalculate the size. If you need to change the size the media displays, it is best to re-encode the media to the desired size using a media encoding tool.

By default, the media that is defined by the Source property plays immediately after the MediaElement object has loaded. To suppress the media from starting automatically, set the AutoPlay property to false.

The following example demonstrates how to add media to your page. The XAML example references an event handler function that must be defined in script and is not shown in the example.

<MediaElement 
    x:Name="media" 
    Source="xbox.wmv" 
    CurrentStateChanged="media_state_changed" 
    Width="300" Height="300"/>

System..::.Object
  System.Windows..::.DependencyObject
    System.Windows..::.UIElement
      System.Windows..::.FrameworkElement
        System.Windows.Controls..::.MediaElement
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker