Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Silverlight 5 RC–TrickPlay and Media Remote Controls

Blogs

Mike Taulty's Blog

Elsewhere

Archives

At the time of the Silverlight 5 beta, I’d put together a simple demo around some of the new media capabilities (not all of them as I’ve never been too hot on the DRM stuff) in Silverlight 5.

This demo involved playing the trailer from the then new X-Men movie and it was a trivial UI that looked like this from a XAML perspective;

<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="Black">
    <MediaElement
      CacheMode="BitmapCache"
      Stretch="Uniform"
      Source="http://localhost/xmen.mov"
      x:Name="media" />
    <!--<MediaElement      
      Stretch="Uniform"
      Source="http://localhost/xmen.mov"
      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:F1\}x}" />
  </Grid>
</UserControl>
and so it’s just a MediaElement whose new PlaybackRate property is bound to a slider and it’s also bound back onto the screen for display purposes. This looks like;

image

You might also notice that in my XAML I have BitmapCache enabled and I also have the hosting HTML page allow hardware acceleration;

image

and that combination allows Silverlight 5 to take full advantage of hardware for its decoding of H.264 indicated by the 3-5% CPU utilisation that I see in playing back this video.

However, at the time of the beta the PlaybackRate had a limitation in that if you changed the value from anything other than 1.0 you would end up with speeded/slowed video but no audio.

In the V5 release candidate this looks to be now implemented and, as promised, not only is the audio speeded up or slowed down but it also has pitch correction so that the audio pitch doesn’t go up or down with the play speed.

The other thing that I could do with respect to a video like this one is to use the new MediaCommands that have been added since the beta.

The UIElement class now has a MediaCommand event on it of type MediaCommandEventHandler which is all pretty self-explanatory;

image

I didn’t have anything suitable to try this out on my PC but I wrote simple code and tried it out on my Mac where it seemed to work out fine with the little supplied remote control (although iTunes kept popping up as well Confused smile but I believe that can be mitigated by using full-screen mode );

Screen shot 2011-09-03 at 16.44.38

and so that would be a nice addition to any media-centric UI.


Posted Mon, Sep 5 2011 9:46 AM by mtaulty