This is a migrated thread and some comments may be shown as answers.

Populate Playlist via web service

2 Answers 65 Views
MediaPlayer
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 2
Adam asked on 02 Sep 2009, 01:04 AM
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 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 04 Sep 2009, 12:01 PM
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.
0
Adam
Top achievements
Rank 2
answered on 04 Sep 2009, 06:09 PM
I think the problem was that the height and width wasn't being set. But it is working now.
THanks
Tags
MediaPlayer
Asked by
Adam
Top achievements
Rank 2
Answers by
Miroslav
Telerik team
Adam
Top achievements
Rank 2
Share this question
or