Monday 10 March 2008

Converting SilverlightAudioPlayer to Silverlight 2.0 Beta 1

I've now got round to revisiting my Silverlight Audio Player control and updating it for Silverlight 2.0 beta 1. The addition of a controls library into Silverlight 2.0 meant that I could ditch a whole load of code straight away.

MediaElement

I also noticed some nice improvements to MediaElement. CurrentState is now an enumeration and the Attributes property has been changed to a dictionary. Unfortunately though, Attributes is still not populated with anything when you load an MP3 file. I had been hoping for it to read the ID3 tags.

Custom Templates

Silverlight Audio Player

To implement the position slider, I made a user control consisting of a green rectangle with a slider on top. The rectangle is used to indicate download progress, and so can be adjusted in width. The slider sets the position

Having done this, I wanted to change the appearance of the slider so I got hold of the default templates for the slider control from MSDN and pasted them into my UserControl.Resources. Unfortunately it didn't compile because of an issue with the way that Colors were added as static resources in the template for the Slider's thumb control. Fortunately, I was able to delete the majority of the code as my Thumb control was simply going to be a circle that changed colour with mouse over. The slider background I changed to be a taller transparent rectangle, so that the download progress rectangle could show through from behind and look like it was filling up the progress bar.

Silverlight Audio Player

So it is remarkably easy to supply your own style to a standard control (so long as you have an example to copy!). The next step will be to see whether I can allow a user to completely override the style for my entire SimplePlayer user control, but I am not sure how easy that will be, as Karen Corby's MIX presentation on Silverlight controls (highly recommended) seemed to suggest that styles could only be applied once and that styleable controls needed to be created in a different way (storing their default styles in a generic.xaml file and using attributes to indicate what "parts" they needed).

What's in the XAP?

One of my goals with Silverlight Audio Player is to make it as simple for people to deploy onto their web-sites as possible. The XAP file will go a long way to making this possible. You can see exactly what is in your XAP file by simply renaming it to .zip and loading it into any zip file extractor. This was useful for me, as I had been a little unsure as to whether any of the files in the ClientBin directory were needed in addition to the XAP file.

RectAnimation

Sadly, the RectAnimation I wanted to be able to animate the clip rectangle of my canvas didn't make it into Silverlight 2.0 beta 1. Maybe next time.

No comments: