
The VideoBrush and MediaElement Relationship
The VideoBrush object's current video frame is determined by its MediaElement. The following illustration depicts the relationship between a MediaElement and a VideoBrush.
MediaElement and VideoBrush
.png)
Note that when a MediaElement loads media and that MediaElement is used by a VideoBrush as its SourceName, the video referenced as the MediaElement Source is downloaded and decoded only one time. You do not suffer significant performance penalties by using a MediaElement and VideoBrush together, even if you choose to have both the MediaElement and VideoBrush display the video.
By pausing or stopping the MediaElement, you pause or stop the VideoBrush. The following example pauses, stops, and plays a VideoBrush by manipulating its MediaElement source.
|
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<MediaElement
x:Name="butterflyMediaElement"
Source="Butterfly.wmv" IsMuted="True"
Opacity="0.0" IsHitTestVisible="False" />
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"
FontFamily="Verdana" FontSize="120"
FontWeight="Bold" TextWrapping="Wrap"
Text="Video">
<!-- Paint the text with video. -->
<TextBlock.Foreground>
<VideoBrush SourceName="butterflyMediaElement" Stretch="UniformToFill" />
</TextBlock.Foreground>
</TextBlock>
<!-- Play -->
<Button MouseLeftButtonDown="PlayMedia" Grid.Row="1" Grid.Column="0"
Width="120" Height="20" Content="Play" />
<!-- Pause -->
<Button MouseLeftButtonDown="PauseMedia" Grid.Row="1" Grid.Column="1"
Width="120" Height="20" Content="Pause" />
<!-- Stop -->
<Button MouseLeftButtonDown="StopMedia" Grid.Row="1" Grid.Column="2"
Width="120" Height="20" Content="Stop" />
</Grid>
|
|
public void PlayMedia(object sender, MouseEventArgs e)
{
butterflyMediaElement.Play();
}
public void StopMedia(object sender, MouseEventArgs e)
{
butterflyMediaElement.Stop();
}
public void PauseMedia(object sender, MouseEventArgs e)
{
butterflyMediaElement.Pause();
}
|
Run this sample.
The previous illustration shows a single VideoBrush, but it is possible for multiple VideoBrush objects to share the same MediaElement.
Although pausing, stopping, or playing a MediaElement affects its VideoBrush, some MediaElement operations and settings have no effect on the VideoBrush. The following MediaElement methods and properties also manipulate a VideoBrush:
The following MediaElement methods and properties do not affect VideoBrush: