Advertisement

Using Encoder Templates in your Silverlight Application

I received a comment regarding the new Expression Encoder SP1 Silverlight player templates and how they can be used within your own application.  Right now the templates appear to stand on their own.  That’s only because the output of an Encoder action will be an encoded file, the template you chose (XAP) and an HTML page to host the Silverlight player application.

But what if you already have an application and are trying to integrate media playback within it?  How can you take advantage of the Encoder templates, but just drop them in your existing application?  Let’s take a quick look.

Let’s say we have an existing application.  For the sake of this post, let’s just show some primitive controls and display a Button and TextBox within some StackPanel layouts:

   1: <UserControl
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     x:Class="ExPlayer.Page"
   5:     Width="640" Height="480" 
   6:     >
   7:  
   8:     <Grid x:Name="LayoutRoot" Background="White">
   9:         <StackPanel Orientation="Horizontal">
  10:             <StackPanel Height="Auto" Width="309">
  11:                 <Button Content="Button"/>
  12:                 <TextBox Text="TextBox" TextWrapping="Wrap"/>
  13:             </StackPanel>
  14:             <StackPanel Height="Auto" Width="250" x:Name="MediaArea"/>
  15:         </StackPanel>
  16:     </Grid>
  17: </UserControl>

Now we want to add a media player using the Encoder templates to our application in the StackPanel labeled MediaArea.  First, we need to get the media player from the template as a control.  Easy enough since the source code for the Expression Encoder Silverlight 2 templates are included.  Browse to your install directory for Expression (usually C:\Program Files\Microsoft Expression\Encoder\Templates\en\) and pick the Silverlight 2 template you want to use.  NOTE: This is only for Silverlight 2 templates, so be sure not to get frustrated at me :-) -- you’ve been forewarned.  I’ll choose the SL2Standard template.  Notice within that folder there is also a Source folder.  Within there is an ExpressionPlayer folder and associated C# source code project.  Open that project in Visual Studio 2008.

Now build the project.  Done.  You now have a control you can use.  Here’s how we’ll do it.

Going back to our own application we need to add a reference to the ExpressionPlayer.dll and MediaPlayer.dll we just built.  Go ahead and do that in your Silverlight application by choosing Add Reference and then pointing to the assembly location.  Now we need to inform our XAML that we’ll be using this control.  Of course if you add these controls to your Visual Studio 2008 toolbox you can drag-and-drop them onto the XAML code surface and it will append the xmlns attribute for you, or we can add it ourself:

   1: <UserControl
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     x:Class="ExPlayer.Page"
   5:     Width="640" Height="480" 
   6:     xmlns:expression="clr-namespace:ExpressionMediaPlayer;assembly=ExpressionPlayer"
   7:     xmlns:ExpressionMediaPlayer="clr-namespace:ExpressionMediaPlayer;assembly=MediaPlayer"
   8:     >

I’ve called my namespace “expression” and “ExpressionMediaPlayer” and you can see I’ve pointed (actually Visual Studio’s Intellisense did it all for me) the namespace to the assembly I just referenced.  Now we can use the control.  Here’s the XAML for adding it to my application and adding a media file that is in my applicaiton:

   1: <UserControl
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     x:Class="ExPlayer.Page"
   5:     Width="640" Height="480" 
   6:     xmlns:expression="clr-namespace:ExpressionMediaPlayer;assembly=ExpressionPlayer"
   7:     xmlns:ExpressionMediaPlayer="clr-namespace:ExpressionMediaPlayer;assembly=MediaPlayer"
   8:     >
   9:  
  10:     <Grid x:Name="LayoutRoot" Background="White">
  11:         <StackPanel Orientation="Horizontal">
  12:             <StackPanel Height="Auto" Width="309">
  13:                 <Button Content="Button"/>
  14:                 <TextBox Text="TextBox" TextWrapping="Wrap"/>
  15:             </StackPanel>
  16:             <StackPanel Height="Auto" Width="250" x:Name="MediaArea">
  17:                 <expression:ExpressionPlayer Width="242" Height="177">
  18:                     <expression:ExpressionPlayer.Playlist>
  19:                         <ExpressionMediaPlayer:PlaylistItem MediaUrl="Lake.wmv"/>
  20:                     </expression:ExpressionPlayer.Playlist>
  21:                 </expression:ExpressionPlayer>
  22:             </StackPanel>
  23:         </StackPanel>
  24:     </Grid>
  25: </UserControl>

Of course you can interact with it via code as well, but getting the control in your app is easy once you know these steps.  Now my application has a fully-functional media playback without me writing any code and being able to integrate it within my existing application.  I might want to change the style of course to fit my application’s experience, but dropping in a few style attributes wouldn’t be that difficult…and I an always make that a part of the Encoder template as well!  Here’s the “after” screenshot of it in play:

You get full functionality out of the player…with one exception.  I’ve noticed that the fullscreen option doesn’t act the same as if the player was the only app.  To be honest I haven’t looked at what it would take to do that,but remember that now the media player is a part of a bigger app and isn’t the application itself.  So “fullscreen” mode is a part of the container Silverlight application and not just the media player…something to watch out for if you expected your embedded media player now to automatically have the same fullscreen functionality.


This work is licensed under a Creative Commons Attribution By license.

  1. 11/3/2008 5:15 PM | # re: Using Encoder Templates in your Silverlight Application
    Tim, thanks for the great tip.
    How many templates does Encoder offer? Or is the above Look & Feel we get?

    Thanks!
    ..Ben
  2. 11/3/2008 8:15 PM | # re: Using Encoder Templates in your Silverlight Application
    Ben: There currently are 21 templates overall (audio/video SL 1 and SL 2). There are 6 new Silverlight 2 templates.
  3. 11/3/2008 10:40 PM | # re: Using Encoder Templates in your Silverlight Application
    I haven't replicated your implementation for the templates, but may be able to lend some guidance on the full screen aspects of the player.

    I've found that when going full screen with a silverlight media element, all other items must be set to a non-shown dimension to allow only the player to go full screen. What we've done is with our own player added soem overloaded events on the control to allow for respective handing of those controls that need to be minimized to be shown.

    In your example it would be the first stackpanel in the parent stackpanel, and set it's width to 0 on the click event for full screen. I dont' know if the templates expose that event though.

    You could also handl the OnFullScreen event of the sl application (I think that is what its called) and set the height or width of those controls or control containers to 0. Add some animations to the events and operates rather gracefully.

    hth
  4. 11/4/2008 5:56 AM | # re: Using Encoder Templates in your Silverlight Application
    Matt: Thanks for the comment. Yes it is entirely possible to do this. I was merely pointing out that if a user is expecting the *same* functionality by just dropping in the control in their application, they needed to understand that the FullScreen mode is a part of the entire application and not just the media player element they put in there. So when embedding one of these templates you would, as you note, have to handle the event and change your hosting application to respond accordingly.
  5. 11/4/2008 11:15 AM | # re: Using Encoder Templates in your Silverlight Application
    Tim,

    Thanks for this great article. Can tooltips be added to the player button? Also,is there a way to disable/hide the fullscreen, closed caption, chapter list, etc... icons?
  6. 11/4/2008 11:18 AM | # re: Using Encoder Templates in your Silverlight Application
    Mauro: Absolutely -- the source is available to you...you can go into the media player and remove those buttons, skin them, whatever.
  7. 11/5/2008 12:58 PM | # re: Using Encoder Templates in your Silverlight Application
    Hi Tim,
    I have added the control to xaml page and depending on some button click want to play the video and here is the code and its not playing the video, I don't knw why? can you please help me?

    PlaylistItem item = new PlaylistItem();
    item.MediaUrl = new Uri(videoInfo.Url, UriKind.RelativeOrAbsolute);
    item.Title = videoInfo.Title;
    item.IsAdaptiveStreaming = true;
    item.FrameRate = SmpteFrameRate.Unknown;

    ExpMediaPlayer.Playlist.Add(item);

    if (ExpMediaPlayer.Playlist.Count > 0)
    {
    ExpMediaPlayer.GoToPlaylistItem(0);
    ExpMediaPlayer.Play();
    }
  8. 11/5/2008 1:37 PM | # re: Using Encoder Templates in your Silverlight Application
    kumar: have you checked the traffic to make sure you aren't running into any cross-domain issues?

  9. 11/5/2008 1:53 PM | # re: Using Encoder Templates in your Silverlight Application
    I'm having a similar issue - calling .Play() doesn't seem to do anything. My videos are all on the same domain as the control.
  10. 11/5/2008 2:20 PM | # re: Using Encoder Templates in your Silverlight Application
    Can someone send me a sample app to look at?
  11. 11/5/2008 3:14 PM | # re: Using Encoder Templates in your Silverlight Application
    Hi Tim,

    Its working now. I used ExpressionMediaPlayer before and it din't work, and when i used ExpressionPlayer it worked.
    Tim, Can you please let us know the difference between ExpressionPlayer and ExpressionMediaPlayer.
    Our videos are on other 'X' website.

    I am new to Silverlight.

    Your blog saved lot of my time and i bacame hero.

    Thank you.
  12. 11/5/2008 3:25 PM | # re: Using Encoder Templates in your Silverlight Application
    kumar: Aha. The difference really is only how the Encoder templates are build. The core player is actually the MediaPlayer (if you look at the source files) and the ExpressionPlayer wraps some functionality around that...thus the need for both assemblies and the difference in controls. Because they are named so similar our eyes didn't catch them :-)
  13. 11/5/2008 3:52 PM | # re: Using Encoder Templates in your Silverlight Application
    Switching the control to ExpressionMediaPlayer:MediaPlayer worked for me too. Thanks!
  14. 11/5/2008 11:57 PM | # re: Using Encoder Templates in your Silverlight Application
    Also if you want to see what is going on with the controls, James is dissecting them for us: www.clarkezone.net/default.aspx
  15. 11/6/2008 11:29 AM | # re: Using Encoder Templates in your Silverlight Application
    Hi Tim,

    can two seperate silverlight apps use same ISO storage using Site Settings. Like you use one silverlight app to store some object in ISO Storage and then use that object from another silverlight app.

    I have read your blog and understood that its not possible even with SiteSettings because each Iso storage is based on XAP Uri.right ?

    Thank you
  16. 11/6/2008 1:13 PM | # re: Using Encoder Templates in your Silverlight Application
    kumar: If the apps are served from the same domain (i.e., foo.mydomain.com/app1.xap and foo.mydomain.com/app2.xap) they can share SiteSettings as they are a part of the same IsoStore group. Each will have it's own area of AppSettings though.
  17. 11/7/2008 6:58 AM | # re: Using Encoder Templates in your Silverlight Application
    Hi Tim,

    Thank you for the Quick response.

    I am using two separate apps.(separate visual studio instances). Both run under localhost right?please Correct me if i am wrong or making a blunder. both run under localhost domain right? but why the apps are not sharing the ISO Storage.

    My code is :

    1) IN First SilverLight App

    private IsolatedStorageSettings siteSettings = IsolatedStorageSettings.SiteSettings;

    var galleryitem = (sender as HyperlinkButton).DataContext as MediaInfo;
    siteSettings.Clear();
    siteSettings.Add("GalleryItem", "galleryitem");
    siteSettings.Save();

    2) In Second Silverlight App

    private IsolatedStorageSettings siteSettings = IsolatedStorageSettings.SiteSettings;

    private TimeSpan currentMediaElementPosition;
    private Popup popUp = new Popup();

    public MultimediaHome()
    {
    InitializeComponent();
    //******************* Isolated Storage Stuff ********************/
    if (siteSettings.Contains("GalleryItem"))
    {
    object ISOItem = siteSettings["GalleryItem"];
    MediaInfo galleryitem = ISOItem as MediaInfo;


    Thank you Tim.
  18. 11/7/2008 9:52 AM | # re: Using Encoder Templates in your Silverlight Application
    Tim,

    Thank you for this valuable info.

    "So “fullscreen” mode is a part of the container Silverlight application and not just the media player"

    I really need to have this feature enabled.

    Is there any work around please?
  19. 11/7/2008 11:00 AM | # re: Using Encoder Templates in your Silverlight Application
    Donovan: The workaround is to to handle the event. "Full Screen" is a mode of a silverlight application, not just a control/component of a part of the application. While the media player has that function...it simply announces to the *application* to change to full screen mode. If you want the media to go full screen, you'll have to watch that event and re-paint the media to your needs over your application.
  20. 11/26/2008 12:38 AM | # re: Using Encoder Templates in your Silverlight Application
    i wan d diagram n code
  21. 12/2/2008 3:29 PM | # re: Using Encoder Templates in your Silverlight Application
    kumar: Are both XAP files served from the same domain?
  22. 12/3/2008 10:53 AM | # re: Using Encoder Templates in your Silverlight Application
    Hi, I tried this and I'm getting the following error in my media player:
    "System.Exception: AG_E_NETWORK_ERROR"

    How I've tried it:
    Giving the MediaUrl value a Relative Path in the SilverLight App
    Giving the MediaUrl value just the FileName and copying the file into the Web App's ClientBin dirctory
    Hosting the media file (wma audio... I've tried mp3 too) on a local website and giving the MediaUrl value that URL (localhost/JMedia/Assets/Audio/01_In_Disguise.wma)

    ... All of these efforts produce the exact same error message.

    Example XAML (that's fun to say :-) )


    localhost/JMedia/Assets/Audio/01_In_Disguise.wma"/>


    Any thoughts?

  23. 12/3/2008 10:58 AM | # re: Using Encoder Templates in your Silverlight Application
    Oops, my XAML didn't come out right in the last post.

    <expression:ExpressionPlayer Width="500" Height="400">
    <expression:ExpressionPlayer.Playlist>
    <ExpressionMediaPlayer:PlaylistItem MediaUrl="localhost/JMedia/Assets/Audio/01_In_Disguise.wma"/>
    </expression:ExpressionPlayer.Playlist>
    </expression:ExpressionPlayer>
  24. 12/3/2008 10:59 AM | # re: Using Encoder Templates in your Silverlight Application
    Tim: when you run the application, what is in the address bar of the browser? Does it start with c:\ or http://? Make sure you aren't running into a cross-scheme situation.
  25. 12/3/2008 11:10 AM | # re: Using Encoder Templates in your Silverlight Application
    The address is:
    http://localhost:4211/Run.aspx

    Run.aspx is calling the Silverlight App.

    Not sure how to tell if it's a cross-scheme situation, or how to correct that.

    -Tim
  26. 12/3/2008 11:15 AM | # re: Using Encoder Templates in your Silverlight Application
    So.

    Copying the wma file into the web app that calls the Silverlight app, then changing the MediaUrl value to: "http://localhost:4211/01_In_Disguise.wma" fixes it.

    Interesting.


  27. 12/3/2008 11:16 AM | # re: Using Encoder Templates in your Silverlight Application
    Weird, it should not make a different if it is the same scheme -- would be interesting to watch the network traffic to see where requests are failing.
  28. 12/3/2008 11:17 AM | # re: Using Encoder Templates in your Silverlight Application
    cross-scheme... duh.
  29. 12/18/2008 2:10 PM | # re: Using Encoder Templates in your Silverlight Application
    Hi Tim,

    I've been reading your blog for some time and would like to seize this opportunity to thank you.

    I'm using a similar user control and would like to host this control on an asp.net page. My problem is that My video library is on an SQL data base, My question is: is there a way to bind programatically the ExpressionMediaPlayer:PlaylistItem to an asp:ObjectDataSource Adapter? if yes How? if not what will be the best approach to achieve this: querying the Videos from the database and then building the PlayListItem from the SQL query result?

    Thanks again
    Moctar
  30. 12/18/2008 2:25 PM | # re: Using Encoder Templates in your Silverlight Application
    Moctar: you'd probably have to modify the source and perhaps expose a public property to set this information or something. or you can wrap the control into some other class and set the initialization parameters accordingly.
  31. 12/22/2008 3:33 PM | # re: Using Encoder Templates in your Silverlight Application
    Where are all the .cs ? When I opened the project in VS 2008, I got full of things there with tons of Exclamation on all the .cs !!
  32. 12/22/2008 4:10 PM | # re: Using Encoder Templates in your Silverlight Application
    Forget my last post. I did reinstall Encoder 2 and the SP1 and now I have them for an unknown reason :)
  33. 12/22/2008 4:30 PM | # re: Using Encoder Templates in your Silverlight Application
    Hi, you said you can interact with it. Can you go a bit further to explain how to set its source ?

    I have it ready in my ClientBin/Videos ready to be streamed
  34. 12/22/2008 4:42 PM | # re: Using Encoder Templates in your Silverlight Application
    I think I did find out how to set my video source but
    as soon as I clicked on the big PLAY button in the center of the player, here's what I had :

    http://pages.videotron.com/gear/crash.jpg
  35. 12/22/2008 4:48 PM | # re: Using Encoder Templates in your Silverlight Application
    Arrrrgh sorry, I forgot to compile the AdaptativeStreaming project and add the dll to my project too :) Now it works like a charm

  36. 12/22/2008 5:02 PM | # re: Using Encoder Templates in your Silverlight Application
    Here I can show what it looks like with a GTA 4 video. This game is very well done. Violent yeah, so don't show it to your children.

    http://gearworld.dyndns.org:8082/devpreview opened between 6:00am and 9:00pm EST

    Last option of the central menu. Enjoy

    I'm wondering if you guys see the video download progress on this player or I have to implement it myself ?
  37. 1/2/2009 7:23 PM | # re: Using Encoder Templates in your Silverlight Application
    Thank you Tim for the tip.

    I tried to do what you suggested but I'm runing through the following problem:

    When I try to play any video that is not in the application(control host Application)ClientBin or a subfolder of it the following exception is raised: System.Exception:AG_E_NETWORK_ERROR. do you know of any approach by which I can play videos that are not stored in the same location as the ClientBin or even hosted on a remote server.

    Remark: I implemented a function that will get the absolute URI of the media source which is passed to the PlayListItem.MediaUrl and I verified that the Path passed by this function to the PlayListItem.MediaUrl is correct.

    Thanks
    Moctar
  38. 1/2/2009 10:19 PM | # re: Using Encoder Templates in your Silverlight Application
    Moctor: if you are using a relative URI the "root" is the location of the XAP file...anything else requires an absolute URI
  39. 1/3/2009 1:19 AM | # re: Using Encoder Templates in your Silverlight Application
    Hi Tim

    Thank you for the quick feedback. My problem seems to be related to any absoluteUri with file:/// as the Scheme for example any videos associated with an absoluteUri like: file:///C:/Experiences/Bear.wmv will throw AG_E_NETWORK_ERROR Exception. at the same time videos associated with an absoluteUri whose scheme is like http:// work fine.
    is the file:// scheme recognized by silverlight2 or is this cross-scheme access issue? Please help

    Thanks
    Moctar
  40. 1/7/2009 11:27 AM | # re: Using Encoder Templates in your Silverlight Application
    Hi Moctar, even though the schemes match, Silverlight isn't aware of anything other than it's application space. So even thought it is rendered using the file scheme, Silverlight cannot arbitrarily seek out a local file that doesn't exist within it's own web application relative to the Silverlight application. This is because it is still a browser application which runs in the secure sandbox.
  41. 1/9/2009 6:53 AM | # re: Using Encoder Templates in your Silverlight Application
    Hi, I uploaded my videos in my silverlight.live.com acct. How can i add it as the source of the media player, almost all the sample is using a video file within the application.

    Thanks,
    Bermo
  42. 2/6/2009 7:34 AM | # re: Using Encoder Templates in your Silverlight Application
    Hi Tim,

    I tried your example above wit the Black Glass template.
    I see the standard player (like the one in your example) but i dont see the Black Glass skin. Do you have any idea?

    Thanks in adcance, Hans.
  43. 2/10/2009 10:17 PM | # re: Using Encoder Templates in your Silverlight Application
    I went through the steps and was successful but the only player I get is the Expression Player not one of the templates. I compiled from the csproj in the SL2AudioOnly folder but the player I get in VS 2008 isn't the SL2AudioOnly but the Expression Media Player. Is there a way to use the other templates or is this one the only one we can pull out? Thanks.
  44. 2/11/2009 10:13 AM | # re: Using Encoder Templates in your Silverlight Application
    David -- each template has an associated Source folder with it, make sure you're grabbing the right one you want to use. Most of the logic is identical with the page.xaml being the difference in the UI.
  45. 2/18/2009 8:50 AM | # re: Using Encoder Templates in your Silverlight Application
    Tim,

    Is it possible to use the templates-skin? I think its the same question as David had, David did you manage to use the skin from the expression 2 players?

    I use the players, after making the dll files available as reference, as a custom user control in the assets library.

    Thanks in advance,

    Hans.
  46. 2/18/2009 8:52 AM | # re: Using Encoder Templates in your Silverlight Application
    Hans, the styles used in the templates are also a part of the source files -- look for player.xaml for those resources.
  47. 2/19/2009 8:14 AM | # re: Using Encoder Templates in your Silverlight Application
    Tim,

    Thanks for your response, but i can't find the player.xaml file in the source folder.

    The xaml files in the Source folder are;
    App
    Page
    generic

    Hans
  48. 2/19/2009 9:02 AM | # re: Using Encoder Templates in your Silverlight Application
    The generic.xaml would be the one where the control templates/styles are defined.
  49. 3/24/2009 6:16 PM | # re: Using Encoder Templates in your Silverlight Application
    Hi, I've successfully embedded one of the templated players into my silverlight application (which is fantastic), but what I can't seem to do is get the selected playlistitem.

    So when I select a playlistitem there doesn't seem to be any event that I can hook into.

    Am I just missing this, or is there some way to add this to the player?

    Thanks,

    Grant.
  50. 4/3/2009 2:20 AM | # re: Using Encoder Templates in your Silverlight Application
    Hello Tim,

    First off, your articles have already helped me out a great deal. So I'd like to thank you in advance.
    I've been trying to add an existing stream to a Silverlight Player template, but I can't seem to find the templates, or more specifically, I can find the templates, but none of them contain a "Source" folder. They just have the MediaDefinition.xml, the player.xaml, a Default.html and a bunch of javascript files, but no XAP files to be found.

    Could this be because I'm running a trial copy of Encoder 2?

    Thanks,
    Pieter
  51. 4/3/2009 8:48 AM | # re: Using Encoder Templates in your Silverlight Application
    Pieter -- make sure you have SP1 for Encoder which will install the Silverlight 2 templates.
  52. 4/3/2009 11:57 AM | # re: Using Encoder Templates in your Silverlight Application
    Ah, I'm sure that's it. Thanks again for your help!
  53. 4/3/2009 9:37 PM | # with silverlight , video rotating and scaling
    Respceted Sir.

    I got your mail id through www.blogs.msdn.com.Sir, i don't have much knowledge in silverlight.Please suggest me some referal sample code links that i can achieve some what as per my requirements where the sample link like http://1dc.net/album.I did not get ant drag and drop option for mediaplayer control but i find the drag and drop with mediaelements.How to do rotation and scaling in video, example,
    One canvas having 6 videos, if we want each video with rotate and scaling icon along with canvas too.
    How to place a video haffazardly or may be overlapped like the above sample url.
    Most of the like youtube with volume increaser icon.
    Thanks in advance Sir.

    With Regards
    Ch.Gayatri subudhi
  54. 4/14/2009 3:45 AM | # re: Using Encoder Templates in your Silverlight Application
    After using encoder templates in my applicatoins I can't hear nothing. The volume control does nothing. Can you any solutions for this issue ?
  55. 5/15/2009 4:29 PM | # re: Using Encoder Templates in your Silverlight Application
    I just downloaded Encoder 2 and there are no Source folders or C# code in the Templates directories. I searched everywhere in the Encoder2 directory and it's child directories. Is this something that is no longer available?
  56. 5/30/2009 11:47 AM | # re: Using Encoder Templates in your Silverlight Application
    Thanks for this example, I followed each step but when I click on the Play button when testing it out and I get this error:
    "An unhandled exception (Unhandled error in Silverlight 2 Application Code: 4004) Category: ManagedRuntimeError Message: System.IO.FileNotFoundException: Could not load assembly 'AdaptiveStreaming, Version 1.0.0.0, Culture..."

    Here is my xaml code:
    <UserControl x:Class="MySLTemplateVideoPlayer.Page"
    xmlns="schemas.microsoft.com/.../presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="500" Height="375"
    xmlns:expression="clr-namespace:ExpressionMediaPlayer;assembly=ExpressionPlayer"
    xmlns:ExpressionMediaPlayer="clr-namespace:ExpressionMediaPlayer;assembly=MediaPlayer"
    >
    <Grid x:Name="LayoutRoot" Background="White">

    <StackPanel Height="Auto" Width="Auto" x:Name="MediaArea" >
    <expression:ExpressionPlayer Width="500" Height="375">
    <expression:ExpressionPlayer.Playlist>

    <ExpressionMediaPlayer:PlaylistItem MediaUrl="Video/Lake.wmv"/>

    </expression:ExpressionPlayer.Playlist>

    </expression:ExpressionPlayer>
    </StackPanel>
    </Grid>
    </UserControl>

    and here is my testpage.html:
    <div id='errorLocation' style="font-size: small;color: Gray;"></div>

    <div id="silverlightControlHost">
    <object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
    <param name="source" value="MySLTemplateVideoPlayer.xap"/>
    <param name="onerror" value="onSilverlightError" />
    <param name="background" value="white" />
    <param name="minRuntimeVersion" value="2.0.31005.0" />
    <param name="autoUpgrade" value="true" />

    <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>

    </object>
    <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
    </div>

    I have the lake.wmv in the silverlight application's bin folder like this: bin/Video/lake.wmv.

    Any advice you can provide would be greatly appreciated, thank you!

  57. 5/31/2009 1:36 PM | # re: Using Encoder Templates in your Silverlight Application
    I figured out the issue I had in the post above, I needed to use the ExpressionMediaPlayer:MediaPlayer instead of ExpressionPlayer, see below:

    <ExpressionMediaPlayer:MediaPlayer Width="Auto" Height="Auto" x:Name="expPlayer">
    <ExpressionMediaPlayer:MediaPlayer.Playlist>
    <ExpressionMediaPlayer:PlaylistItem MediaUrl=""/>
    </ExpressionMediaPlayer:MediaPlayer.Playlist>

    </ExpressionMediaPlayer:MediaPlayer >
  58. 5/31/2009 1:40 PM | # re: Using Encoder Templates in your Silverlight Application
    Quick question, I am using this template player now but it does not seem to recognize markers. I used Expression Encoder 2 to add markers to a video file and I can preview it in the browser in Expression Encoder and that works fine. When I drop the same video file (and supporting files) into this template player in my app (built using the steps in this blog), the markers don't show up in the chapter button.

    Should this functionality be packaged in the template?
  59. 5/31/2009 1:49 PM | # re: Using Encoder Templates in your Silverlight Application
    Jack -- I believe it should, but I'd have to look at the code...you may have to ensure that that marker code is included as well and not interfering with other XAML elements that might exist in the application.
  60. 6/3/2009 3:35 PM | # re: Using Encoder Templates in your Silverlight Application
    Tim, there's a problem with customizing a template and then using it in your own app. I did everything as you described and it worked, but even though I edited the template it shows the original version of it. The reason for this is because there doesn't appear to be a way to apply a Style to the player once you get it into your own app. You cannot edit the core template, you can only create a new style. But when you do that and build the new template, importing the dll's into your app brings the template in and the default Style is applied to your player. I tried adding the proper style attribute to the xaml: <expression:ExpressionPlayer Width="640" Height="360" Name="ExpPlayer" Style="{StaticResource MyStyle}"/> and even copying the Style resource from the template app into my app. None of these solutions work.

    How can I use a customized encoder template in my silverlight app?
  61. 6/3/2009 5:09 PM | # re: Using Encoder Templates in your Silverlight Application
  62. 6/5/2009 12:00 PM | # re: Using Encoder Templates in your Silverlight Application
    How can I bubble up a MarkerReached event to my JavaScript? Basically I need to modify other html objects on a web page when a marker in the video is reached. I am not using asp.net in this instance (ie. not running on a web server, using an hta).

    Here is the relevant snippet:
    <object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%" id="silverlightVideoControlIntro">
    <param name="source" value="ClientBin/MediaPlayerTemplate.xap"/>
    <param name="onerror" value="onSilverlightError" />
    <param name="background" value="black" />
    <param name="minRuntimeVersion" value="2.0.31005.0" />
    <param name="autoUpgrade" value="true" />
    <param name="initParams" value='' />

    <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>

    </object>

    I am using the MediaPlayerTemplate.xap (from SL2Standard).

    Thanks in advance... your blogs have been very helpful.
  63. 6/5/2009 12:23 PM | # re: Using Encoder Templates in your Silverlight Application
    Jack -- you'd have to modify the code to expose some scriptable methods.
  64. 6/5/2009 2:25 PM | # re: Using Encoder Templates in your Silverlight Application
    I tried this and it seems to do what I need in just a couple lines of code:

    In the MediaPlayer.OnMediaElementMarkerReached() method:

    HtmlPage.Window.Invoke("globalJSMethod_MarkerReached", e.Marker.Time);
    this.Pause();

    -JL
  65. 6/8/2009 5:17 PM | # re: Using Encoder Templates in your Silverlight Application
    Asking again. Please help:

    I just downloaded Encoder 2 and there are no Source folders or C# code in the Templates directories. I searched everywhere in the Encoder2 directory and it's child directories. Is this something that is no longer available?
  66. 7/9/2009 6:07 AM | # re: Using Encoder Templates in your Silverlight Application
    @J Silver
    You have to install Service Pack 1 to get the templates. The current service pack is not included in the trial download.

    Greetings Carlos

 
Please add 3 and 5 and type the answer here:
First time here? You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting! (hide this)