Page view counter

Building A HyperVideo Player – 1

 


 

 

In a previous posting, I began a fast and furious mini-tutorial on building a hyper-video player. In this segment, I'll demonstrate how to:

  • Use Encoder to add markers to a video
  • Use Encoder to create a player
  • Modify the player Encoder creates using templates
  • Have the player respond to each marker as it is encountered

To begin, you'll need a bit of video. I downloaded the 4th segment of the video on Building a Skinnable Custom Control and then cut out the middle to create a very abridged version that runs just over a minute.

AbridgedMovie

I then imported that video into Encoder, and added markers as shown in the earlier blog entry.

Use Encoder to create a player

With the markers in place I turned to creating my player. Again, this is reviewed in the previous blog entry so I won't repeat that here, but now we're ready to actually make the changes.  For today's exercise, this is a process of eliminating those controls that we don't need. We'll start by opening the player in Expression Blend and as with any custom control you may now ask to edit a copy of the template,

EditPlayerTemplate

You are prompted, as usual to pick a name and to choose whether to put the template into the file or into App.xaml (for the entire application). We'll choose the latter. Once these choices are made you are dropped into the template editor, the view states are revealed as are the parts of the media player.

TemplatedPlayer

This allows you to drill down into the player and simply delete those controls we won't need, including the entire set of "miscControls,"

miscControls

 

 

 

 

which are conveniently highlighted on the player to indicate which controls you are about to assassinate,

image

In the same way, I proceeded to eliminate the buttons used for rapid navigation

NavButtons

Once these were deleted the player was simplified and ready for use.

SimplifiedPlayer

 

 

Responding to the Markers

I'd like to tell you that responding to the markers that we added to the video involves a bit of tricky programming, and you're lucky you found my blog because I can show you how to do it right….

Opening the project in Visual Studio reveals otherwise. You'll remember that what we've created is a template for the ExpressionPlayer class that was emitted by Encoder and that is found in ExpressionPlayerClass.cs:

namespace ExpressionMediaPlayer
{
public class ExpressionPlayer : MediaPlayer

Stripping out the using statements and comments reveals that the class created by Encoder is just a specialization of Media Player. MediaPlayer's source is provided as well. Opening MediaPlayer.cs and scrolling down to the Events region reveals this:

public event TimelineMarkerRoutedEventHandler MarkerReached;

That is the event we want to respond to; it is fired every time the player encounters a marker in the video.

The EventArgs type that we are passed is well documented in the standard Silverlight documentation, which includes among other things sample code that makes our work embarrassingly easy,

public void OnMarkerReached(object sender, TimelineMarkerRoutedEventArgs e)
{
timeTextBlock.Text = e.Marker.Time.Seconds.ToString();
typeTextBlock.Text = e.Marker.Type.ToString();
valueTextBlock.Text = e.Marker.Text.ToString();
}

All we need is a TextBlock to display the values we'll receive when we hit the marker. Open Page.xaml and add two rows to the grid, and a TextBlock in the second row,

  <Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition
Height="9*" />
<RowDefinition
Height="0.5*" />
</Grid.RowDefinitions>
<ExpressionPlayer:ExpressionPlayer
Margin="0,0,0,0"
x:Name="myPlayer"
Style='{StaticResource ExpressionPlayerBlogVersion }'
Grid.Row='0' />
<TextBlock
x:Name='Message'
Grid.Row='1' />
</Grid>

You can now implement the event handler in Page.xaml.cs,

public partial class Page : UserControl
{

public Page( object sender, StartupEventArgs e )
{
InitializeComponent();
myPlayer.OnStartup( sender, e );
myPlayer.MarkerReached +=
new TimelineMarkerRoutedEventHandler( myPlayer_MarkerReached );
}

void myPlayer_MarkerReached( object sender,
TimelineMarkerRoutedEventArgs e )
{
Message.Text = e.Marker.Text + " at " + e.Marker.Time.Seconds.ToString() +
" seconds."
}
}

The result, as we hoped, is that the player shows the video and when it encounters a marker, it shows the name of the marker and the time the marker was hit. The easiest way to test this is to navigate to the output directory you designated in encoder,

EnodedDirectory

and pick up a copy of the the Default.html and the .wmv file output by encoder.  Drop these in the debug directory of the encoder folder

TestingFromDebug

Double click on Default.html and "let 'er rip!"

WorkingHyperVideo

Note the marker indicated at just below the (cropped) player.  Be careful when you recompile, the default.html in the Encoder project will be over-written.

 

Previous: HyperVideo: Getting Started       Next: HyperVideo Put To Work

Published Monday, January 05, 2009 9:53 PM by jesseliberty

Comments

# Hypervideo ??? Getting Started - Jesse Liberty - Silverlight Geek

Pingback from  Hypervideo ??? Getting Started - Jesse Liberty - Silverlight Geek

# Dew Drop - January 6, 2009 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - January 6, 2009 | Alvin Ashcraft's Morning Dew

Tuesday, January 06, 2009 9:29 AM by Dew Drop - January 6, 2009 | Alvin Ashcraft's Morning Dew

# Silverlight Travel &raquo; Building A HyperVideo Player

Pingback from  Silverlight Travel &raquo; Building A HyperVideo Player

Tuesday, January 06, 2009 11:01 AM by Silverlight Travel » Building A HyperVideo Player

# re: Building A HyperVideo Player – Phase 1

Great article.  Just a note on this.. if you use the Edit in Blend option, you can simply recompile in Blend, re-encode in Encoder and you'll have your edited player without having to overwrite XAP files manually.  If you subsequently make more changes in Blend same applies.  Due to a feature in Expression Encoder called partial rebuild, the video will only be encoded the first time.. subsequent "re-encodes" will use cached results and will thus be instantanious.

Tuesday, January 06, 2009 4:27 PM by clarkezone

# Silverlight Cream for December 06, 2009 -- #477

In this issue: James Bacon, Chris Anderson, Jesse Liberty, Expression Blend and Design Blog, Laurent

Tuesday, January 06, 2009 4:43 PM by Community Blogs

# re: Building A HyperVideo Player – Phase 1

hi;

i have created a new example based on "Building A HyperVideo Player – Phase 1".

I hope you will enjoy it.

M. Yasar Ozden

http://guide.ceit.metu.edu.tr

Tuesday, January 06, 2009 4:46 PM by myozden

# re: Building A HyperVideo Player – Phase 1

sorry for the message i have forgotten the link.

guide.ceit.metu.edu.tr/.../VideoPlayerThemedTestPage.html

M. Yasar Ozden

Tuesday, January 06, 2009 4:49 PM by myozden

# Erstellen eines HyperVideo Player - Phase 1 at Programming with Silverlight, WPF &amp; .NET

Pingback from  Erstellen eines HyperVideo Player - Phase 1 at Programming with Silverlight, WPF &amp; .NET

# Video Wiki – Status and Overview

This page will serve as the Overview of the VideoWiki Application to be developed as part of the AgOpenSource

Thursday, July 30, 2009 11:06 AM by Jesse Liberty - Silverlight Geek

# Video Wiki – Status and Overview

This page will serve as the Overview of the VideoWiki Application to be developed as part of the AgOpenSource

Thursday, July 30, 2009 1:01 PM by Microsoft Weblogs