.NET (RSS)

Collecation of .NET and programming related 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.

Quick sample for starting with Silverlight

This is my first try of using Silverlight and it is based on the Silverlight v1.0 Beta and the first of the Silverlight Quickstarts: lesson 01. My aim is to reuse this project and use it as a scratch project for my next articles.

You will need to install the Silverlight v1.0 Beta plugin on your computer.

There are going to be only 3 files in the same folder:

  • An html files that will run in the browser called index.htm.
  • A javascript  file which handles all the plumbing, Silverlight.js
  • A xaml file called myxaml.xaml  containing the content will be displayed inside the silverlight.

 

My Xaml called myxaml.xaml file displaying the content 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>

You can play around with the xaml file and changing the different attributes of the ellipse, reload the html file to see the changes.

My HTML file (index.htm) looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>SilverLight - First Try</title>
    <script type="text/javascript" src="Silverlight.js"></script>
  </head>
  <body>
   <!-- Where the Silverlight control will go-->
 <div id="mySilverlightControlHost">
 </div>
 <script type="text/javascript">
  function createMySilverlightControl()
  { 
      Sys.Silverlight.createObject(
          "myxaml.xaml",                  // Source property value.
          parentElement,                  // DOM reference to hosting DIV tag.
          "mySilverlightControl",         // Unique control ID value.
          {                               // Control properties.
              width:'300',                // Width of rectangular region of
                                          // control in pixels.
              height:'300',               // 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>
  </body>
</html>

Once you have these files in the same folder, then launch the index.htm and if everything works ok then you should see a nice big blue circle on the page displayed.

CAPICOM error with ClickOnce

Technorati tags: .NET, CAPICOM, ClickOnce

I have a project using ClickOnce for deployment and from time to time, when I want to publish a new version of my application I receive the following error:

SignTool Error: Signtool requires CAPICOM version 2.1.0.1 or higher. Please copy the latest version of CAPICOM.dll into the directory that contains SignTool.exe. If CAPICOM.dll exists, you may not have proper permissions to install CAPICOM.

This problem is happening, because the CAPICOM.dll is not registered correctly and the solution for this is the following:

Copy CAPICOM.dll from Program Files\Common\Microsoft Shared\CAPICOM to the SignTool.exe directory.

I successfully resolved this issue by copying the .dll to this location, but this time no matter what I did I received this error, when I tried to publish. I was pulling my hair, so I decided to check out the deployment option, then after not finding annything there I went to the Signing. I noticed there that I was using a test certificate, what was expired already. Creating a new test certificate solved my problem.

Orcas' Very Large Number

The only living person ever known to count to infinity was Chuck Norris. He did it twice. No you can do this too with the help of the new numeric type BigInteger from the System.Numeric namespace. All you need to do is to reference the System.Core.dll and refrence the System.Numeric namespace in your app.

Counting to Infinity


I understand that the above example is not a really usefull one. See also: Introducing: System.Numeric.BigInteger for a more usefull example.

SQL Server Compact Edition

When first heard about the SQL Server 2005 Express Edition I thought this will be something like an updated MSDE - although even MSDE was a bit fat and heavy for my taste, especially for using to embedd DB to Winforms applications. I had hopes that SQL Express will be something lighter and easier to deply and embedd to your rich client apps. I could not be more wrong with this. I have new hope now and it is manifesting in this 5 letter acronym SQLSCE ( it is 6 letters actually, but I am not done with my first cofee yet).

SQLSCE stands for the SQL Server Compact Edition. It seems that they took SQL Server Everywhere from the Windows Mobile platform and made it possible to deploy and use on the PC as well, so this is now truly everywhere.

SQL Server Compact Edition product page at microsoft.com.

There are plenty of whitepapers available on the product page including a guide that helps you to decide, when to use Compact Edition and when to use Express:

SQL 2005 Compact Edition is recommended to use, when:

  • When you want essential relational database functionality in a compact footprint
  • Ideal for mobile and desktop applications, including occasionally-connected
  • Embeddable in applications
  • Free to download, develop, deploy, and redistribute

Not to use when:

  • When you need to run SQL as a service 
  • When you need multi user database server
  • When you need the full functionality of SQL Server

MSDN SQL Server 2005 Compact Edition How-to Tutorials.

There are some really good how-to articles on MSDN covering some of the features of the Compact Edition, but I missed the very basic one.

The one with starting from scratch

First you will need to create a database file. This is normally a file with a .sdf extension:

  1. Start the IDE and on Data menu choose Add New Data Source
  2. Select Database and click on New Connection
  3. Select Microsoft SQL Server 2005 Compact Edition
  4. In Connection Properties click on Cerate
  5. Specify the file name and password and click ok.
  6. The wizard will also ask you if you want to add this file to your project and if you want to store connection string in your application settings file.

The One with the Drunken Visual Studio

Arriving home tonight and wanted to a little bit of my hobby pet project, just for relaxing, so I fired up Visual Studio .NET 2005 and saw that the menu items are all duplicated and all the toolbars are duplicated too.

 

I had no idea what happened with it, because this morning everything was fine, when I was doing the morning session on my recreational pet project. I tried about a zillion and two things plus searching the web like crazy, but the one trick that helped at the and was the following:

 

  • Exit Visual Studio
  • Navigate to your %USERPROFILE% in explorer.
  • Go to the following folder %USERPROFILE%\Local Settings\Application Data\Microsoft and rename the Visual Studio folder to something else, like __Visual Studio.
  • Do the same with %USERPROFILE%\\Application Data\Microsoft\ and the Visual Studio folder.
  • Start Visual Studio again.

Let's hope that this can save some times for others!

OSX's Expose on Vista

Simon created My Expose utility for Vista. My Expose is the OS X's Expose implementation using DWM and Windows SDK.

My Exposé : A Mac OS X Exposé implementation for Windows VISTA from Simon on (dot) NET.

IronPython 1.0 released

I just read the announcement on James Huguin's blog, that he and his team released IronPython 1.0. I think this is a very important release as it shows the coming age of dynamic languages on the .NET platform. I expect to see Ruby soon on the .NET platform and AppleScript or a similar scripting language would be really cool.
I decided to learn a new language each year and I am getting really interested in these dynamic languages, so I think this year's winner is going to be either python or ruby....