MediaElement.CurrentState Propriedade

Definição

Obtém o status deste MediaElement.

public:
 property MediaElementState CurrentState { MediaElementState get(); };
MediaElementState CurrentState();
public MediaElementState CurrentState { get; }
var mediaElementState = mediaElement.currentState;
Public ReadOnly Property CurrentState As MediaElementState

Valor da propriedade

O estado atual deste MediaElement. O estado pode ser um dos seguintes (conforme definido na enumeração MediaElementState ): Buffering, Closed, Opening, Paused, Playing ou Stopped. O valor padrão é Closed.

Exemplos

O exemplo a seguir demonstra uma maneira de exibir o CurrentState de um MediaElement. Ele cria um MediaElement e vários botões para controlar a reprodução de mídia. Para exibir o estado atual do MediaElement, o exemplo registra-se para o evento CurrentStateChanged e usa um manipulador de eventos para atualizar um TextBlock.

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <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" />

    <TextBlock
Grid.Column="0" Grid.Row="2" Margin="10" 
FontSize="12">CurrentState:</TextBlock>

    <TextBlock 
x:Name="mediaStateTextBlock"
Grid.Column="1" Grid.Row="2" Margin="0,10,0,0"
FontSize="12"></TextBlock>

</Grid>
private void StopMedia(object sender, RoutedEventArgs e)
{
    media.Stop();
}
private void PauseMedia(object sender, RoutedEventArgs e)
{
    media.Pause();
}
private void PlayMedia(object sender, RoutedEventArgs e)
{
    media.Play();
}
private void Media_State_Changed(object sender, RoutedEventArgs e)
{
    mediaStateTextBlock.Text = media.CurrentState.ToString();
}
Private Sub StopMedia(ByVal sender As Object, ByVal e As RoutedEventArgs)
    media.Stop()
End Sub

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

Private Sub PlayMedia(ByVal sender As Object, ByVal e As RoutedEventArgs)
    media.Play()
End Sub
Private Sub Media_State_Changed(ByVal sender As Object, ByVal e As EventArgs)
    mediaStateTextBlock.Text = media.CurrentState.ToString
End Sub

Aplica-se a