One of the developers from one of my media customers asked me how they would implement the thumbnail preview while scrubbing in a Silverlight video player. He was turned onto the idea from seeing that feature in the Netflix Watch Instantly Silverlight player.
I thought that would be something that others could use, so I decided to use Silverlight Media Framework player to demonstrate it. It turns out that Expression Encoder has the capability to create thumbnail images from a video during encoding. You can use this capability to just create images of a video at regular intervals.
<?xml version="1.0" encoding="utf-16"?> <!--Created with Expression Encoder version 3.0.1332.0--> <JobFile Version="3.0"> <Job OutputDirectory="C:\Users\mischero\Documents\Expression\Expression Encoder\Output" JobId="MISCHERO1 1-21-2010 2.28.38 PM"> <MediaFiles> <MediaFile Source="C:\Users\Public\Videos\Sample Videos\Wildlife.wmv" MarkerThumbnailJpegCompression="100"> <OutputFormat> <WindowsMediaOutputFormat AudioProfile="SourceProfile" VideoProfile="SourceProfile" /> </OutputFormat> <Markers> <Marker Time="00:00:01" Value="" GenerateKeyFrame="True" GenerateThumbnail="True" /> </Markers> </MediaFile> </MediaFiles> </Job> </JobFile>
private void positionElement_MouseMove(object sender, MouseEventArgs e) { if (this.positionElement.IsDragging) { if (this.ThumbnailInterval <= 0) { return; } var seconds = System.Convert.ToInt32(Math.Floor(positionElement.Value + 0.5)); var image2 = seconds - seconds % this.ThumbnailInterval; var image1 = image2 - this.ThumbnailInterval; var image3 = image2 + this.ThumbnailInterval; this.SetThumbnailImage(this.thumbnail1, image1); this.SetThumbnailImage(this.thumbnail2, image2); this.SetThumbnailImage(this.thumbnail3, image3); } } private void SetThumbnailImage(Image image, int index) { if (image == null) { return; } BitmapImage bitmap; if (this.thumbnailImages.TryGetValue(index, out bitmap)) { image.Source = bitmap; } }
<local:ThumbnailPlayer x:Name="Player" Content="Player" Margin="8" Style="{StaticResource ThumbnailPlayerStyle}" ThumbnailLocation="Thumbnails/Wildlife" ThumbnailInterval="1"> <local:ThumbnailPlayer.MediaElement> <Microsoft_SilverlightMediaFramework_Player:CoreSmoothStreamingMediaElement Source=http://localhost:6801/ThumbnailDemoSite/ClientBin/Wildlife.wmv AutoPlay="False"/> </local:ThumbnailPlayer.MediaElement> </local:ThumbnailPlayer>
The end result is a player with thumbnails. You can download the source code here.
Updated 1/22/2010 - You can now see a demo here.