Silverlight:mediaelement State

Source: Internet
Author: User
Tags tostring silverlight

You can detect state changes by using the currentStateChanged event by detecting the MediaElement state by using the CurrentState property. This overview includes the use of these APIs and provides information about transitions between different MediaElement states.

MediaElement

The current state of the MediaElement (buffering, Closed, Error, Opening, paused, Playing, or Stopped) affects users who use the media. For example, if a user is trying to view a large video, MediaElement may remain in the buffering state for a long time. In this case, you might want to provide a hint in the user interface (UI) that you can't play the media yet. When the buffer is complete, you may want to indicate that the media can now be played.

Using CurrentState and currentStateChanged

The following example shows a method to display the CurrentState of a MediaElement. It creates a MediaElement and several buttons to control media playback. To display the current state of the MediaElement, this example registers the currentStateChanged event and uses an event handler to update the TextBlock.

Xaml

<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= "
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= ">CurrentState:</TextBlock>"
<textblock
X:name= "Mediastatetextblock"
grid.column= "1" grid.row= "2" margin= "0,10,0,0"
Fontsize= "></TextBlock>"
</Grid>

Vb

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

C#

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, EventArgs e)
{
mediaStateTextBlock.Text = media.CurrentState.ToString();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.