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

Selecting items from the playlist

4 Answers 74 Views
MediaPlayer
This is a migrated thread and some comments may be shown as answers.
Hardy
Top achievements
Rank 1
Hardy asked on 19 Nov 2008, 08:15 PM
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

4 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 20 Nov 2008, 04:10 PM
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.
0
Hardy
Top achievements
Rank 1
answered on 20 Nov 2008, 05:00 PM
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:

        public Page()  
        {  
            InitializeComponent();  
 
            mediaPlayer.Loaded += new RoutedEventHandler(mediaPlayer_Loaded);  
              
            mediaPlayer.AutoPlay = true;  
        }  
 
        void mediaPlayer_Loaded(object sender, RoutedEventArgs e)  
        {  
            // Pick a random item for testing  
            RadMediaItem tobeplayed = mediaPlayer.Items[2] as RadMediaItem;  
            mediaPlayer.CurrentItem = tobeplayed;  
        } 


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

0
Accepted
Kiril Stanoev
Telerik team
answered on 21 Nov 2008, 08:12 PM
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.
0
Hardy
Top achievements
Rank 1
answered on 22 Nov 2008, 07:52 PM
Thank you very much, Kiril, for both the hotfix and the sample project. This is most excellent and solves my problem.

Kind regards,

Hardy
Tags
MediaPlayer
Asked by
Hardy
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Hardy
Top achievements
Rank 1
Share this question
or