MediaState Enumeration
Defines the potential states of a MediaElement.
XAML |
<objectproperty="EnumerationValue" .../>
|
Scripting |
value = "EnumerationValue"
|
Enumeration Values
Value | Description |
---|---|
Buffering | The MediaElement is loading the media for playback. Its Position does not advance during this state. If the MediaElement was already playing video, it continues to display the last displayed frame. |
Closed | The MediaElement contains no media. The MediaElement displays a transparent frame. |
Error | The MediaElement encountered an error during media playback. If the MediaElement was playing video, it continues to display the last displayed frame. This MediaElement changes to this state after raising the MediaFailed event. |
Opening | The MediaElement is validating and attempting to open the Uri specified by its Source property. While in this state, the MediaElement queues any Play, Pause, or Stop commands it receives and processes them if the media is successfully opened. |
Paused | The MediaElement does not advance its Position. If the MediaElement was playing video, it continues to display the current frame. |
Playing | The MediaElement is playing the media specified by its source property. Its Position advances forward. |
Stopped | The MediaElement contains media but is not playing or paused. Its Position is 0 and does not advance. If the loaded media is video, the MediaElement displays the first frame. |
Media state is typically used to adjust the visual appearance and current functionality of media transport controls.
Examples
The following example demonstrates one way to display the CurrentState of a MediaElement. It creates a MediaElement and several buttons for controlling media playback. To display the current state of the MediaElement, the example registers for the CurrentStateChanged event and uses an event handler to update a TextBlock.
XAML |
---|
<Canvas xmlns="https://schemas.microsoft.com/client/2007" xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" Width="300" Height="300"> <MediaElement x:Name="media" Source="xbox.wmv" CurrentStateChanged="media_state_changed" Width="300" Height="300"/> <!-- Stops media playback.--> <Canvas MouseLeftButtonDown="media_stop" Canvas.Left="10" Canvas.Top="265"> <Rectangle Stroke="Black" Height="30" Width="55" RadiusX="5" RadiusY="5"> <Rectangle.Fill> <RadialGradientBrush GradientOrigin="0.75,0.25"> <GradientStop Color="Orange" Offset="0.0" /> <GradientStop Color="Red" Offset="1.0" /> </RadialGradientBrush> </Rectangle.Fill> </Rectangle> <TextBlock Canvas.Left="5" Canvas.Top="5">stop</TextBlock> </Canvas> <!-- Pauses media playback. --> <Canvas MouseLeftButtonDown="media_pause" Canvas.Left="70" Canvas.Top="265"> <Rectangle Stroke="Black" Height="30" Width="55" RadiusX="5" RadiusY="5"> <Rectangle.Fill> <RadialGradientBrush GradientOrigin="0.75,0.25"> <GradientStop Color="Yellow" Offset="0.0" /> <GradientStop Color="Orange" Offset="1.0" /> </RadialGradientBrush> </Rectangle.Fill> </Rectangle> <TextBlock Canvas.Left="5" Canvas.Top="5">pause</TextBlock> </Canvas> <!-- Begins media playback. --> <Canvas MouseLeftButtonDown="media_begin" Canvas.Left="130" Canvas.Top="265"> <Rectangle Stroke="Black" RadiusX="5" RadiusY="5" Height="30" Width="55"> <Rectangle.Fill> <RadialGradientBrush GradientOrigin="0.75,0.25"> <GradientStop Color="LimeGreen" Offset="0.0" /> <GradientStop Color="Green" Offset="1.0" /> </RadialGradientBrush> </Rectangle.Fill> </Rectangle> <TextBlock Canvas.Left="5" Canvas.Top="5">play</TextBlock> </Canvas> <TextBlock Canvas.Left="190" Canvas.Top="265" FontSize="12">CurrentState:</TextBlock> <TextBlock x:Name="mediaStateTextBlock" Canvas.Left="190" Canvas.Top="280" FontSize="12"></TextBlock> </Canvas> |
JavaScript |
---|
function media_stop(sender, args) { sender.findName("media").stop(); } function media_pause(sender, args) { sender.findName("media").pause(); } function media_begin(sender, args) { sender.findName("media").play(); } function media_state_changed(sender, args) { var mediaStateTextBlock = sender.findName("mediaStateTextBlock"); var media = sender.findName("media"); mediaStateTextBlock.Text = media.CurrentState; } |
Applies To
See Also
Media Overview
MediaElement States
CurrentState
CurrentStateChanged