MediaElement.CurrentState Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the status of the MediaElement.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)


Public ReadOnly Property CurrentState As MediaElementState
public MediaElementState CurrentState { get; }

Property Value

Type: System.Windows.Media.MediaElementState
The current state of the MediaElement. The state can be one of the following (as defined in the MediaElementState enumeration): Buffering, Closed, Opening, Paused, Playing, or Stopped.
The default value is Closed.


Dependency property identifier field: CurrentStateProperty

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

CurrentState and CurrentStateChanged are most relevant if your application defines UI that permits transport control of the media (ultimately using MediaElement methods such as Play, Stop, etc.) Certain media states imply that calls to such APIs will not be able to execute immediately, which you could choose to reflect in your UI 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 Play 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.

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

Your code should not rely on states occurring in an exact order. The CurrentStateChanged reports that a change has occurred, and CurrentState reports the current state, but subframe transitory states might not raise CurrentStateChanged. The intention of the CurrentStateChanged / CurrentState API is that you can use the reported information for changes to UI, and reporting every subframe transitory state is not necessary for this scenario.

If the source is an ASX file, state is captured for the media that is the current media 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 will begin downloading the next item in the playlist 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.

Run this sample

        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*"/>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />

    <MediaElement CurrentStateChanged="Media_State_Changed"
        x:Name="media" Source="xbox.wmv" Width="300" Height="300" 
                  Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" />

    <!-- Stops media playback.-->
    <Button Click="StopMedia" 
     Grid.Column="0" Grid.Row="1" Content="Stop" />

    <!-- Pauses media playback. -->
    <Button Click="PauseMedia" 
     Grid.Column="1" Grid.Row="1" Content="Pause" />

    <!-- Begins media playback. -->
    <Button Click="PlayMedia" 
     Grid.Column="2" Grid.Row="1" Content="Play" />

Grid.Column="0" Grid.Row="2" Margin="10" 

Grid.Column="1" Grid.Row="2" Margin="0,10,0,0"

Private Sub StopMedia(ByVal sender As Object, ByVal e As RoutedEventArgs)
End Sub

Private Sub PauseMedia(ByVal sender As Object, ByVal e As RoutedEventArgs)
End Sub

Private Sub PlayMedia(ByVal sender As Object, ByVal e As RoutedEventArgs)
End Sub
Private Sub Media_State_Changed(ByVal sender As Object, ByVal e As EventArgs)
    mediaStateTextBlock.Text = media.CurrentState.ToString
End Sub
private void StopMedia(object sender, RoutedEventArgs e)
private void PauseMedia(object sender, RoutedEventArgs e)
private void PlayMedia(object sender, RoutedEventArgs e)
private void Media_State_Changed(object sender, EventArgs e)
    mediaStateTextBlock.Text = media.CurrentState.ToString();

Version Information


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.