Populate Playlist via web service

3 posts, 0 answers
  1. Adam
    Adam avatar
    9 posts
    Member since:
    Nov 2008

    Posted 01 Sep 2009 Link to this post

    Below is the code behind for my mediaplayer.  I am trying to populate the playlist with information retrieved from a WCF web service.  The player loads and the web service works as far as retrieving data, but i can't set the RadMediaPlayer.ItemsSource with the collection of RadMediaItems. Where am I going wrong?

    public partial class MainPage : UserControl 
        { 
            ObservableCollection<RadMediaItem> itemsSource = new ObservableCollection<RadMediaItem>(); 
     
            public MainPage() 
            { 
                InitializeComponent(); 
                mPlayer.ItemsSource = itemsSource; 
            } 
     
            private void LoadPlaylist() 
            { 
                GalleryPlaylistClient client = new GalleryPlaylistClient(); 
                client.GetPlaylistMediaCompleted += new EventHandler<GetPlaylistMediaCompletedEventArgs>(client_GetPlaylistMediaCompleted); 
                client.GetPlaylistsAsync(); 
            } 
     
            void client_GetPlaylistMediaCompleted(object sender, GetPlaylistMediaCompletedEventArgs e) 
            { 
                var items = e.Result; 
                
                foreach (MediaFile item in items) 
                { 
                    RadMediaItem media = new RadMediaItem(); 
                    media.Source = new Uri(item.SourceUrl, UriKind.RelativeOrAbsolute); 
                    media.Title = item.Title; 
                    media.Description = item.Description; 
                    media.VideoHeight = item.Height; 
                    media.VideoWidth = item.Width; 
                    media.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(item.ThumbnailUrl, UriKind.RelativeOrAbsolute)); 
                    itemsSource.Add(media); 
                } 
            } 
     
            private void mPlayer_Loaded(object sender, System.Windows.RoutedEventArgs e) 
            { 
                LoadPlaylist(); 
            } 
        } 

  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 04 Sep 2009 Link to this post

    Hello Adam,

    I created a simple application using your code and it seems to work as expected, I have attached it here.

    1. You say that you cannot set the ItemsSource of the MediaPlayer. Do you get an exception?
    2. Can you confirm that you are generating MediaPlayer items (at least 1)?
    3. Also please check that the video height / width that you set to the MediaItem is not 0.

    Hopefully we will be able to get to the root of the issue,

    Sincerely yours,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Adam
    Adam avatar
    9 posts
    Member since:
    Nov 2008

    Posted 04 Sep 2009 Link to this post

    I think the problem was that the height and width wasn't being set. But it is working now.
    THanks
Back to Top