Code-Behind on Chapter

2 posts, 0 answers
  1. Ramin Aminloo
    Ramin Aminloo avatar
    35 posts
    Member since:
    Dec 2009

    Posted 15 Jan 2010 Link to this post

    Hi, I am unable to populate the chapters using code-behind. What am I doing wrong? Playlist gets created but without chapters.

               var items = e.Result;
                ObservableCollection<RadMediaItem> itemsSource = new ObservableCollection<RadMediaItem>();

                foreach (OnlineTraining item in items)
                {
                    RadMediaItem media = new RadMediaItem();
                    media.Source = new Uri(item.FileName, UriKind.RelativeOrAbsolute);
                    media.Title = item.Title;
                    media.Description = item.Description;
                    media.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(item.ImageSource, UriKind.RelativeOrAbsolute));
                    ObservableCollection<RadMediaChapter> mediachapter = new ObservableCollection<RadMediaChapter>();
                    RadMediaChapter chapter = new RadMediaChapter();
                    chapter.Position = "00:00:05";
                    chapter.Title = "test";
                    mediachapter.Add(chapter);

                     chapter = new RadMediaChapter();
                    chapter.Position = "00:10:00";
                    chapter.Title = "test2";
                    mediachapter.Add(chapter);

                    chapter = new RadMediaChapter();
                    chapter.Position = "00:20:00";
                    chapter.Title = "test2";
                    mediachapter.Add(chapter);


                    chapter = new RadMediaChapter();
                    chapter.Position = "00:30:00";
                    chapter.Title = "test2";
                    mediachapter.Add(chapter);


                    chapter = new RadMediaChapter();
                    chapter.Position = "00:40:00";
                    chapter.Title = "test2";
                    mediachapter.Add(chapter);

                    chapter = new RadMediaChapter();
                    chapter.Position = "00:50:00";
                    chapter.Title = "test2";
                    mediachapter.Add(chapter);

                    media.Items.Add(mediachapter);
                    itemsSource.Add(media);

                }
                RadMediaPlayer1.ItemsSource = itemsSource;
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 15 Jan 2010 Link to this post

    Hello Martin,

    The problem is where you say media.Items.Add(mediachapter); It means that you are adding a collection(ObservableCollection<RadMediaChapter> mediachapter) to the Items of media. Instead you should add each chapter to the Items of the media item:

    foreach (OnlineTraining item in items)
    {
        RadMediaItem media = new RadMediaItem();
        media.Source = new Uri(item.FileName, UriKind.RelativeOrAbsolute);
        media.Title = item.Title;
        media.Description = item.Description;
        media.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(item.ImageSource, UriKind.RelativeOrAbsolute));
        RadMediaChapter chapter = new RadMediaChapter();
        chapter.Position = "00:00:05";
        chapter.Title = "test";
        media.Items.Add(chapter);
     
        chapter = new RadMediaChapter();
        chapter.Position = "00:10:00";
        chapter.Title = "test2";
        media.Items.Add(chapter);
     
        chapter = new RadMediaChapter();
        chapter.Position = "00:20:00";
        chapter.Title = "test2";
        media.Items.Add(chapter);
     
        chapter = new RadMediaChapter();
        chapter.Position = "00:30:00";
        chapter.Title = "test2";
        media.Items.Add(chapter);
     
        chapter = new RadMediaChapter();
        chapter.Position = "00:40:00";
        chapter.Title = "test2";
        media.Items.Add(chapter);
     
        chapter = new RadMediaChapter();
        chapter.Position = "00:50:00";
        chapter.Title = "test2";
        media.Items.Add(chapter);
     
        itemsSource.Add(media);
    }

    Give it a try and let me know if you still experience the same issue. I'd be glad to further assist you.

    Greetings,
    Kiril Stanoev
    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
Back to Top