Selecting items from the playlist

5 posts, 1 answers
  1. Hardy
    Hardy avatar
    5 posts
    Member since:
    Sep 2012

    Posted 19 Nov 2008 Link to this post

    Hi,

    I was wondering if it is possible to create (either programmatically or in XAML) a playlist and then programmatically pick an item from the list and start the playback. Currently the player always plays the first item of the playlist and I haven't been able to figure out how to dynamically set it to play another (random) item from the list.

    Any hints would be much appreciated. Thanks.

    Regards,

    Hardy
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 20 Nov 2008 Link to this post

    Hi Hardy,

    RadMediaPlayer has a property exactly for that purpose - CurrentItem.
    This property is of type RadMediaItem and when you set it, RadMediaPlayer plays whatever is set.
    For example, assume that you have a playlist with 5 videos and you want to play the 3rd one. Then what you should do is:

    this.radMediaPlayer1.CurrentItem = this.radMediaPlayer1.Items[1] as RadMediaItem; 

    I have attached a sample project demonstrating that functionality. Please, let us know how this works for you and if you have any additional questions do not hesitate to contact us.

    Regards,
    Kiril Stanoev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. Hardy
    Hardy avatar
    5 posts
    Member since:
    Sep 2012

    Posted 20 Nov 2008 Link to this post

    Thank you very much for your swift answer and the sample project, Kiril.

    I had discovered the CurrentItem property but have not quite been able to implement what I want to achieve, as CurrentItem seems to be ignored by the player when set on load, in the constructor or any other *early* place I could think of, in order for the desired item to start playing right away without additional user interaction. Setting AutoPlay to true always plays the first item in the playlist, no matter what I set the CurrentItem property to.

    Here is what the prototype code looks like at the moment:

    1         public Page()  
    2         {  
    3             InitializeComponent();  
    4  
    5             mediaPlayer.Loaded += new RoutedEventHandler(mediaPlayer_Loaded);  
    6               
    7             mediaPlayer.AutoPlay = true;  
    8         }  
    9  
    10         void mediaPlayer_Loaded(object sender, RoutedEventArgs e)  
    11         {  
    12             // Pick a random item for testing  
    13             RadMediaItem tobeplayed = mediaPlayer.Items[2] as RadMediaItem;  
    14             mediaPlayer.CurrentItem = tobeplayed;  
    15         } 


    And this is what I need to do eventually: 

    • my application has a single page hosting the player with a playlist of several videos.
    • other pages link to the page with the player and will have an identifier for the video to be played in the query string
    • as soon as as the player loads, it should play the desired item from the playlist.
    • once the visitor has watched the video, they should be able to browse the playlist and view any other videos they might be interested in.

    I have considered modifying the sequence of the playlist and moving the desired video to the beginning of the list, but since these are training videos that need to be in a precise sequence, this isn't really an option.

    I was also able to trap the player's MediaOpened-event and set my desired video there, but this seems more like a hack than a real solution.

    So basically my question boils down to this: where/when/how do I have to set CurrentItem so the desired item will be played when the page loads?

    Thanks again for your help so far. We're getting there.

    Regards,

    Hardy

  5. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 21 Nov 2008 Link to this post

    Hi Hardy,
    Indeed RadMediaPlayer had an issue setting the CurrentItem property on Loaded. You can find a hotfix in the attachment. Also you can find a sample project that implements your request.
    Please let us know how this works for you. 

    Sincerely yours,
    Kiril Stanoev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Hardy
    Hardy avatar
    5 posts
    Member since:
    Sep 2012

    Posted 22 Nov 2008 Link to this post

    Thank you very much, Kiril, for both the hotfix and the sample project. This is most excellent and solves my problem.

    Kind regards,

    Hardy
Back to Top
DevCraft banner