added samples
[windows-sources.git] / sdk / samples / WPFSamples / MediaGallery / vb / mediaelementexample.xaml.vb
blobe194e6d1ec9cc8aa69cc66155f478aa2ddd26ae3
2 Imports System
3 Imports System.Windows
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
13 Namespace SDKSample
15 Partial Class MediaElementExample
16 Inherits Page
18 ' Play the media.
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
23 ' already running.
24 myMediaElement.Play()
26 ' Initialize the MediaElement property values.
27 InitializePropertyValues()
28 End Sub 'OnMouseDownPlayMedia
31 ' Pause the media.
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
39 ' Stop the media.
40 Sub OnMouseDownStopMedia(ByVal sender As Object, ByVal args As MouseButtonEventArgs)
41 ' The Stop method stops and resets the media to be played from
42 ' the beginning.
43 myMediaElement.Stop()
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)
50 End Sub
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)
55 End Sub
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
61 End Sub
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
71 End Sub
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)
78 End Sub
80 End Class 'MediaElementExample
81 End Namespace 'SDKSample