4 Imports System
.Windows
.Controls
5 Imports System
.Windows
.Documents
6 Imports System
.Windows
.Navigation
7 Imports System
.Windows
.Shapes
8 Imports System
.Windows
.Data
9 Imports System
.Windows
.Media
10 Imports System
.Windows
.Input
15 Partial Class MediaElementExample
19 Sub OnMouseDownPlayMedia(ByVal sender
As Object, ByVal args
As MouseButtonEventArgs
)
21 ' The Play method will begin the media if it is not currently active or
22 ' resume media if it is paused. This has no effect if the media is
26 ' Initialize the MediaElement property values.
27 InitializePropertyValues()
28 End Sub 'OnMouseDownPlayMedia
32 Sub OnMouseDownPauseMedia(ByVal sender
As Object, ByVal args
As MouseButtonEventArgs
)
33 ' The Pause method pauses the media if it is currently running.
34 ' The Play method can be used to resume.
35 myMediaElement
.Pause()
36 End Sub 'OnMouseDownPauseMedia
40 Sub OnMouseDownStopMedia(ByVal sender
As Object, ByVal args
As MouseButtonEventArgs
)
41 ' The Stop method stops and resets the media to be played from
44 End Sub 'OnMouseDownStopMedia
47 ' Change the volume of the media.
48 Public Sub ChangeMediaVolume(ByVal sender
As Object, ByVal args
As RoutedPropertyChangedEventArgs(Of
Double))
49 myMediaElement
.Volume
= System
.Convert
.ToDouble(volumeSlider
.Value
)
52 ' Change the speed of the media.
53 Public Sub ChangeMediaSpeedRatio(ByVal sender
As Object, ByVal args
As RoutedPropertyChangedEventArgs(Of
Double))
54 'myMediaElement.SpeedRatio = System.Convert.ToDouble(speedRatioSlider.Value)
57 ' When the media opens, initialize the "Seek To" slider maximum value
58 ' to the total number of miliseconds in the length of the media clip.
59 Public Sub Element_MediaOpened(ByVal sender
As Object, ByVal args
As RoutedEventArgs
)
60 timelineSlider
.Maximum
= myMediaElement
.NaturalDuration
.TimeSpan
.TotalMilliseconds
63 ' Jump to different parts of the media (seek to).
64 Public Sub SeekToMediaPosition(ByVal sender
As Object, ByVal args
As RoutedPropertyChangedEventArgs(Of
Double))
65 Dim SliderValue
As Integer = CType(timelineSlider
.Value
, Integer)
67 ' Overloaded constructor takes the arguments days, hours, minutes, seconds, miniseconds.
68 ' Create a TimeSpan with miliseconds equal to the slider value.
69 Dim ts
As New TimeSpan(0, 0, 0, 0, SliderValue
)
70 myMediaElement
.Position
= ts
73 Private Sub InitializePropertyValues()
74 ' Set the media's starting Volume and SpeedRatio to the current value of the
75 ' their respective slider controls.
76 myMediaElement
.Volume
= System
.Convert
.ToDouble(volumeSlider
.Value
)
77 'myMediaElement.SpeedRatio = System.Convert.ToDouble(speedRatioSlider.Value)
80 End Class
'MediaElementExample
81 End Namespace
'SDKSample