tags:

views:

509

answers:

1

Dear fellow programmers at Stackowverflow.com or anyone knowledgeable,

I am presently building my first real life application using RadControls for Silverlight from Telerik. So far I pretty much like it and controls whether in Silverlight or from third parties are really powerful. This particular application is essentially a video player built around RadMediaPlayer. Now you do need to understand specifics of RadMediaPlayer in order to help me. As it stands, my issue is related straight to core Silverlight programming, my language of choice being C#. I have two external XML files. First one contains configuration information like width and height of video player. Here is how it looks like in present form.

    <?xml version="1.0" encoding="utf-8"?>
 <video_player_config>
         <video_contentdescription_file>http://localhost:83/JSVP_Video_player/Playlist.media.xml&lt;/video_contentdescription_file&gt;
         <videoplayer_width>300</videoplayer_width>
         <videoplayer_height>300</videoplayer_height>
     </video_player_config>

The second one contains data for media items in the following structure:

<mediaItems>

    <mediaItem>
      <title></title>
      <description> </description>
      <mediaUrl> </mediaUrl>
      <imageUrl> </imageUrl>

etc.

Now I have written a static class named “SichulaVideoPlayerConfig” that opens XML confi-guration file using WebClient and then parses it using LINQ to XML. This works fine on its own. The trouble is that when I call SichulaVideoPlayerConfig.LoadConfigFile during Appli-cation_Startup in app.xaml.cs, the data from XML configuration file are not yet there and the player UI initializes as empty. It seems to me that the problem is related to the asynchronous nature of WebClient.OpenReadAsync method. I understand that it runs on different thread than UI. Because of that my UI initializes and yet data from XML file are still not available. I kindly ask for help in how to overcome this unwanted situation. A working code example would be most welcome and I have already read much theory but to no avail. Kindly please, please, help me.

Jan Sichula (Slovak Republic)

http://sichula.temelios.sk/ (English website for friends – family photos, videos and newsletter archive)

A: 

Were you using Kirupa's tutorial to achieve this? From the second page, you need to register for the DownloadStringCompleted event of the WebClient and at that point you can access the configuration info:

http://www.kirupa.com/blend_silverlight/loading_xml_sl2_pg2.htm

The problem seems to be (as you suspect) that you're trying to access the config settings from a static class without checking whether or not the settings are actually loaded - you need a new strategy for loading your configuration settings. Two options:

  1. Continue your current strategy and add a SettingsLoaded event to your static SichulaVideoPlayerConfig class. Your config class should wait for WebClient.DownloadStringCompleted to fire, load the Xml into the settings properties, then fire its SettingsLoaded event. At that point the UI is free to configure the video player.

  2. Take another route and store the settings in a place that will be immediately available to your player. Try this:

http://jonas.follesoe.no/ConfiguringSilverlight2ApplicationsUsingTheWCFConfigurationFile.aspx

Your static config class will immediately be able to load the player settings, you'll no longer need the WebClient class. I would recommend this approach and have implemented it numerous times; it works well.

Good luck!

James Cadd