Share via


MediaElement Object

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

XAML
<MediaElement .../>
Scripting
To create an object using scripting, see the CreateFromXAML method.

Properties

Attributes, AutoPlay, AudioStreamCount, AudioStreamIndex, Balance, BufferingProgress, BufferingTime, CanPause, CanSeek, Canvas.Left, Canvas.Top, Canvas.ZIndex, Clip, CurrentState, Cursor, DownloadProgress, Height, IsMuted, Markers, Name, NaturalDuration, NaturalVideoHeight, NaturalVideoWidth, Opacity, OpacityMask, Position, RenderTransform, RenderTransformOrigin, Resources, Source, Stretch, Tag, Triggers, Volume, Width

Methods

AddEventListener, CaptureMouse, Equals, FindName, GetHost, GetParent, GetValue, Pause, Play, ReleaseMouseCapture, RemoveEventListener, SetSource, SetValue, Stop

Events

BufferingProgressChanged, CurrentStateChanged, DownloadProgressChanged, Loaded, MarkerReached, MediaEnded, MediaFailed, MediaOpened, MouseEnter, MouseLeave, MouseLeftButtonDown, MouseLeftButtonUp, MouseMove

Remarks

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 UIElement-defined properties Height and Width. However, for best performance, avoid explicitly setting the width and height of a MediaElement. Insead, 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.

Not all media formats and protocols are supported by Silverlight. See Supported Media Formats and Protocols for more information.

In networks where a proxy server exists, special settings on the client may be required before streaming will work in Silverlight. For more information, see Proxy Servers and Streaming in Silverlight.

Examples

The following example demonstrates how to add media to your page.

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

See Also

Media Overview
Supported Media Formats and Protocols
Using the CreateFromXAML Method