
Chapter 10: Designing Silverlight Applications | 293 |
m_isPlaying = true;
}
}
}
}
VB:
Partial Public Class MainPage
Inherits UserControl
Public Sub New()
InitializeComponent()
VideoPlayer.AutoPlay = False
End Sub
Dim m_isPlaying As Boolean = False
Private Sub StartStopButton_Click(
ByVal sender As System.Object,
ByVal e As System.Windows.RoutedEventArgs)
If (m_isPlaying) Then
VideoPlayer.Stop()
StartStopButton.Content = "Start"
m_isPlaying = False
Else
VideoPlayer.Play()
StartStopButton.Content = "Stop"
m_isPlaying = True
End If
End Sub
End Class
By default, the MediaElement starts playing the Source video as soon as the application loads, so I set AutoPlay to false in the
This is a quick demo of how to work with the MediaElement control, but there’s much more you can do, such as pausing, tracking buffering, checking video position, and more. All you need to do is either capture events of the MediaElement control or use controls like buttons and sliders to interact with MediaElement, as the example shows in Listing