Note: these are early notes based on some initial experiments with the Silverlight 5 beta, apply a pinch of salt to what you read.
Following up on that previous post I thought I’d try out the new TrickPlay feature of Silverlight 5 that lets you speed up or slow down the speed at which you’re watching a video and so I took my playback of my “The Bourne Ultimatum” trailer and added a couple of simple controls to it ( there’s no code needed for this stuff – it’s a pure binding scenario ).
The key thing in this XAML is the new PlaybackRate property on the MediaElement control and I use that in bindings;
<UserControl x:Class="SilverlightApplication7.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <MediaElement CacheMode="BitmapCache" Stretch="Fill" Source="trailer.mp4" x:Name="media" /> <Slider HorizontalAlignment="Center" VerticalAlignment="Bottom" Opacity="0.4" Width="192" Minimum="0.25" Maximum="8" Margin="0,0,0,24" SmallChange="0.25" LargeChange="0.5" Value="{Binding ElementName=media,Path=PlaybackRate,Mode=TwoWay}" /> <TextBlock Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Bottom" Opacity="0.3" Margin="0,0,24,24" FontSize="144" Text="{Binding ElementName=media,Path=PlaybackRate,StringFormat=\{0\}x}" /> </Grid> </UserControl>
and that gives me enough UI to slow down or speed up my video and get a picture of what speed I’m currently running at;
and slowing down that trailer let’s you see some of the action a little better although, amazingly, it still looks pretty fast at 0.25x of the original play speed.
Note – if you try this out yourself then you’ll encounter a “feature” of the beta in that if the play speed is anything other than 1.0 you’ll notice that the audio disappears.
In the RTM version, the audio will be present and will also have smarts to attempt to preserve the original pitch of the audio track rather than raising it up or lowering it down with the play speed. That feature’s not there in the beta so what you get instead is silence right now.