Bagikan melalui


MediaElement.CurrentState Properti

Definisi

Mendapatkan status MediaElement ini.

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

Nilai Properti

Status MediaElement saat ini. Statusnya bisa menjadi salah satu hal berikut (seperti yang didefinisikan dalam enumerasi MediaElementState ): Buffering, Closed, Opening, Paused, Playing, atau Stop. Nilai defaultnya adalah Tertutup.

Contoh

Contoh berikut menunjukkan salah satu cara untuk menampilkan CurrentState dari MediaElement. Ini membuat MediaElement dan beberapa tombol untuk mengontrol pemutaran media. Untuk menampilkan status MediaElement saat ini, contoh mendaftar untuk peristiwa CurrentStateChanged dan menggunakan penanganan aktivitas untuk memperbarui 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

Berlaku untuk