In an email dialog today I saw someone asking how he could use an existing Encoder 2 template for existing media or streaming URIs when you don’t have something to encode. After a few explanations, he replied that someone should blog this – and I agree :-).
So what did he mean? Well, when you use Expression Encoder, you are typically going to be encoding media to a format to consume. Encoder also gives you an additional option in the output settings to generate a media player for that encoded content. These are all based on templates that I’ve previously written about that are available in the product as well is the source code for you to extend.
But what if you have a media file that doesn’t need encoding or you have a streaming URI and you don’t need to encode anything, but want the player? To some it might not be so obvious so let me try to walk you through the steps.
You need the player
First you need the player. The XAP that is, of the template you want to use. There are essentially two ways of going about getting this:
- Getting the MediaPlayerTemplate.xap file from an existing output you already did (that used the same template you want)
- Building the XAP using the source of the templates and building it from scratch (requires .NET compiler or Visual Studio)
Obviously if you have the XAP of your desired template, you are ready to proceed. If you don’t, then you’ll need to proceed to step 2. Here’s what you’ll do:
Building the Player
First, find the template you want. These are located in C:\Program Files\Microsoft Expression\Encoder 2\Templates\en (note: if you are on 64-bit or a different language, this path may differ slightly). Within here you’ll see a list of templates by name. Find the one you want and within that folder there is a Source directory. That’s what you want. I highly recommend actually moving the source files to a different place rather than edit directly in the templates directory. There is a Visual Studio 2008 solution/project file in there and you can open it up and compile.
As long as you are in there…
If you don’t need all the features of the template (i.e., Adaptive Streaming, etc) consider reading James Clarke’s post on removing some of those references and still creating the same template, but with reduced functionality.
Once compiled (remember to choose the right configuration - i.e., Release, Debug - for your needs), you’ll have in the Bin directory of that project the MediaPlayerTemplate.xap file you need.
So how can you compile the player template without media? The Encoder 2 Silvelright 2 templates are completely parameter driven. If you notice in any existing encoded project output (look at the default.html file generated) you’ll see the object tag used to host the player. It may look something like this:
Notice the initParams option? If you aren’t familiar, you can send Silverlight 2 applications parameters using this method. There’s a video walk-through on using initParams you can view on the Silverlight community site. The key area here (among the other options) for media URIs is the playlist parameter. Singling that one out you’ll see the structure looks like this:
This sample above represents a single media file with chapter markers. The bare minimum for a single media URI would be:
So if you have a streaming URI (i.e., mms://mysite.com/live-baseball-game.asx) you would use this playlist structure:
and then in your HTML page you could have something like this for the full implementation (noting to use the appropriate width/height for your needs):
It is important to note that if you know the other parameters like framerate, etc. you should provide as much information you can for the playListItem node, but I’m just noting the bare minimum above.
Can I do this in code?
I suspect people would not be using the code concept as much but I just wanted to point it out here.
So having the MediaPlayerTemplate.xap file is really all you need. Anything else can be sent as parameters either via the object tag, the XAML control or in code. This enables being able to really re-use the template you desire without having to run an encoder job just to get the template and change the code.
Hope this helps!