This is a migrated thread and some comments may be shown as answers.
Configuring and populating RadMediaPlayer items from external XML file
1 Answer 52 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
JanSichulaJr asked on 01 Jul 2009, 11:50 AM

Dear Telerik or anyone knowledgeable,


I am presently building my first real life application using RadControls for SL. So far I pretty much like it and controls from Telerik are really powerful. This particular application is essentially a video player built around RadMediaPlayer.

               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" ?>







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






      <description> </description>

      <mediaUrl> </mediaUrl>

      <imageUrl> </imageUrl>




Now I have written a static class named “SichulaVideoPlayerConfig” that opens XML configuration 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 Application_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) (English website for friends – family photos, videos and newsletter archive)


1 Answer, 1 is accepted

Sort by
Kiril Stanoev
Telerik team
answered on 02 Jul 2009, 02:37 PM
Hello Jan,

One advice I can give you is to start your UI only after the XML has been loaded. What I mean is, in Application_Startup to insert your logic for downloading the XML file:

private void Application_Startup(object sender, StartupEventArgs e) 
    WebClient client = new WebClient(); 
    client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted); 
    client.OpenReadAsync(new Uri("MediaItems.xml", UriKind.Absolute)); 

In my case I am downloading an XML file (MediaItems.xml) that is hosted in the ClientBin directory of my Web project.

Once the XML has been downloaded, you can instantiate your main page (ex. Page.xaml) by passing it the stream.

void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
    Stream reply = (Stream)e.Result; 
    StreamReader s = new StreamReader(reply); 
    this.RootVisual = new Page(s.ReadToEnd()); 

This is how my Page class looks like:

public partial class Page : UserControl 
    public Page() 
    public Page(string stream) : this() 

Give this approach a try and let me know how it works for you. If you have additional questions or problems, let us know immediately.

Kiril Stanoev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Asked by
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Share this question