June 2007 - Posts

Simple video playback with Silverlight

The main feature of Silverlight that I am really excited about is the capability playing back videos. It does mean that we do not have to embed WMP controls on the HTML page anymore, but it will be possible to playback Windows Media Videos with Silverlight only, that means that Silverlight does not rely on WMP for video playback and it will be possible to playback Windows Media videos on other platforms as well. I have not tried this capability on the Mac yet, so I do not know how well the video playback works or does not work. But here is a quick way how to do this:

I am reusing the files from my Silverlight scratch project:

Quick sample for starting with Silverlight

The first step is to get a video file and copy to folder, where the .html and .xaml file will be. Right now I am trying to play video only locally. Then you will need to create a new .xaml file (player.xaml), which looks like this:

<Canvas Width="800" Height="800" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   <Canvas x:Name="VideoLayer">
  <MediaElement x:Name="VideoElement" Canvas.Top="0" Canvas.Left="0" Stretch="Uniform" AutoPlay="True" Source="butterfly.wmv" />
  </Canvas>
 </Canvas>

In the .xaml snippet we have a Canvas and a MediaElement inside the Canvas. The source attribute is set to butterfly.wmv - this is the name of the video I copied to the same folder with the .html and .xaml files - and the autoplay property set to true, so it will start playing right away.

The next step is to modify the .html file, so it loads the right .xaml file (player.xaml) and change the size, so it can display the whole video.

So it will look like this:

 <script type="text/javascript">
  function createMySilverlightControl()
  { 
      Sys.Silverlight.createObject(
          "player.xaml",                  // Source property value.
          parentElement,                  // DOM reference to hosting DIV tag.
          "mySilverlightControl",         // Unique control ID value.
          {                               // Control properties.
              width:'720',                // Width of rectangular region of
                                          // control in pixels.
              height:'480',               // Height of rectangular region of
                                          // control in pixels.
              inplaceInstallPrompt:false, // Determines whether to display
                                          // in-place install prompt if
                                          // invalid version detected.
              background:'#D6D6D6',       // Background color of control.
              isWindowless:'false',       // Determines whether to display control
                                          // in Windowless mode.
              framerate:'24',             // MaxFrameRate property value.
              version:'0.9'               // Control version to use.
          },
          {
              onError:null,               // OnError property value --
                                          // event handler function name.
              onLoad:null                 // OnLoad property value --
                                          // event handler function name.
          },
          null);                          // Context value -- event handler function name.
  }
       
       
        // Retrieve the div element you created in the previous step.
        var parentElement =
            document.getElementById("mySilverlightControlHost");
       
        // This function creates the Silverlight control.
        createMySilverlightControl();
       
 </script>

 

Now the only thing is left to launch the html page and enjoy the video.

Free Expression Design and Expression Blend training from Lynda.com

Lynda.com is offering their Expression Blend and Expression Design trainings for free for everyone. Both trainings are 6 hours long.

Expression Blend

http://movielibrary.lynda.com/html/modPage.asp?ID=384 - Getting started with Expression Blend.

In Getting Started with Expression Blend , Lee Brimelow covers all the basics that every designer and developer of WPF and Silverlight content needs to know. He starts with an overview of how Expression Blend fits into WPF and Silverlight workflows, then guides viewers through the process of creating and manipulating objects, building timeline-based animations, and exporting compositions into XMAL for use in Visual Studio.


http://movielibrary.lynda.com/html/modPage.asp?ID=359  - Expression Blend Beta Preview.

Expression Blend is a new interactive authoring tool from Microsoft that is available for free as a public beta. Instructor Lee Brimelow explores all of the application's features and capabilities, from the user interface panels to creating and importing assets. He also covers integrating 3D content, using WPF text controls, layout controls, and user input controls, and creating animated effects. Expression Blend Beta Preview gives a comprehensive insider look at the new version of Expression Blend before it hits the shelves.

 

Expression Design

 http://movielibrary.lynda.com/html/modPage.asp?ID=339 - Getting Started with Expression Design.

From basic vector-based drawings to professional three-dimensional graphics built with Live Effects, Ted LoCascio covers the full range of possibilities in Getting Started with Expression Design. He starts by explaining Expression Design's interface and how to work with documents, then moves on to cover working with objects and applying fills, strokes, and effects for best results. Exercise files accompany this training.