<Window x:Class="SoundAndVideo.AnimatedVideoWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AnimatedVideoWindow" Height="450" Width="400">
<Window.Resources>
<Storyboard x:Key="MediaStoryboardResource">
<MediaTimeline Storyboard.TargetName="media" Source="test.mpg" FillBehavior="HoldEnd"
RepeatBehavior="Forever"></MediaTimeline>
<DoubleAnimation Storyboard.TargetName="media" Storyboard.TargetProperty="(MediaElement.RenderTransform).(RotateTransform.Angle)"
To="360" Duration="0:0:2" RepeatBehavior="Forever"></DoubleAnimation>
</Storyboard>
</Window.Resources>
<StackPanel>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="cmdPlay">
<EventTrigger.Actions>
<BeginStoryboard Name="MediaStoryboard" Storyboard="{StaticResource MediaStoryboardResource}"/>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="cmdStop">
<EventTrigger.Actions>
<StopStoryboard BeginStoryboardName="MediaStoryboard"/>
</EventTrigger.Actions>
</EventTrigger>
</StackPanel.Triggers>
<Button Name="cmdPlay">Play (Declarative)</Button>
<Button Name="cmdStop">Stop (Declarative)</Button>
<Button Click="cmdPlayCode_Click">Play (Code)</Button>
<MediaElement Name="media" Grid.Row="1" Stretch="None" RenderTransformOrigin="0.5,0.5" >
<MediaElement.RenderTransform>
<RotateTransform></RotateTransform>
</MediaElement.RenderTransform>
</MediaElement>
</StackPanel>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes
Imports System.Windows.Media.Animation
Namespace SoundAndVideo
Public Partial Class AnimatedVideoWindow
Inherits System.Windows.Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub cmdPlayCode_Click(sender As Object, e As RoutedEventArgs)
Dim timeline As New MediaTimeline(New Uri("test.mpg", UriKind.Relative))
timeline.RepeatBehavior = RepeatBehavior.Forever
Dim clock As MediaClock = timeline.CreateClock()
Dim player As New MediaPlayer()
player.Clock = clock
Dim videoDrawing As New VideoDrawing()
videoDrawing.Rect = New Rect(150, 0, 100, 100)
videoDrawing.Player = player
Dim brush As New DrawingBrush(videoDrawing)
Me.Background = brush
clock.Controller.Begin()
End Sub
End Class
End Namespace