Export (0) Print
Expand All
Expand Minimize



Gets the status of the MediaElement object.

value = object.CurrentState

Type: MediaState

The current state of the MediaElement object. The state can be one of the following (as defined in the MediaState enumeration): Buffering, Closed, Error, Opening, Paused, Playing, or Stopped.

This property is read-only. The default value is Closed.

When the value of this property changes, the MediaElement raises its CurrentStateChanged event.

CurrentState and CurrentStateChanged are most relevant if your application defines a user interface that permits transport control of the media (ultimately using MediaElement methods such as Play and Stop). Certain media states imply that calls to such methods will not be able to execute immediately, which you could choose to reflect in your user interface by temporarily providing visual feedback, or you could also provide fallback information based on state from within your event handlers. For example, if the current state is Buffering, a call to the Play method will not be immediately responsive until the state changes to another state such as Playing or Paused.

Changing the value of Source on a MediaElement will change the state to Opening, unless Source is set to null, in which case the state is Closed.

If the state is Error, that state change will also raise the MediaFailed event.

The meanings of the states and the possible application responses to them are influenced by the type of media that is being played. For example, live streaming media cannot be paused and will never enter the Paused state.

Your code should not rely on states occurring in an exact order. The CurrentStateChanged event reports that a change has occurred, and CurrentState reports the current state, but subframe transitory states might not raise CurrentStateChanged. CurrentStateChanged and CurrentState are provided so you can use the reported information to change the user interface, and reporting every subframe transitory state is not necessary for this scenario.

If the source is an ASX file, state is captured for the current media that is being processed from the playlist. States for referenced media in the playlist that are not the current media being processed are not captured. Downloading progress to the other media in the playlist occurs in the background, and the next item in the playlist will begin downloading 20 seconds before the end of the current entry.

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.

  Width="300" Height="300">

    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">
        <RadialGradientBrush GradientOrigin="0.75,0.25">
          <GradientStop Color="Orange" Offset="0.0" />
          <GradientStop Color="Red" Offset="1.0" />
    <TextBlock Canvas.Left="5" Canvas.Top="5">stop</TextBlock>

  <!-- Pauses media playback. -->
  <Canvas MouseLeftButtonDown="media_pause"
    Canvas.Left="70" Canvas.Top="265">
    <Rectangle Stroke="Black"
      Height="30" Width="55" RadiusX="5" RadiusY="5">
        <RadialGradientBrush GradientOrigin="0.75,0.25">
          <GradientStop Color="Yellow" Offset="0.0" />
          <GradientStop Color="Orange" Offset="1.0" />
    <TextBlock Canvas.Left="5" Canvas.Top="5">pause</TextBlock>

  <!-- Begins media playback. -->
  <Canvas MouseLeftButtonDown="media_begin"
    Canvas.Left="130" Canvas.Top="265">
    <Rectangle Stroke="Black" RadiusX="5" RadiusY="5"
      Height="30" Width="55">
        <RadialGradientBrush GradientOrigin="0.75,0.25">
          <GradientStop Color="LimeGreen" Offset="0.0" />
          <GradientStop Color="Green" Offset="1.0" />
    <TextBlock Canvas.Left="5" Canvas.Top="5">play</TextBlock>

    Canvas.Left="190" Canvas.Top="265"

    Canvas.Left="190" Canvas.Top="280"

function media_stop(sender, args)

function media_pause(sender, args)

function media_begin(sender, args)

function media_state_changed(sender, args)
    var mediaStateTextBlock = 
    var media = sender.findName("media");
    mediaStateTextBlock.Text = media.CurrentState;

Community Additions

© 2014 Microsoft