How to set the PlayList Index for Mediaplayer(Expr

2019-08-27 17:38发布

I have a Mediaplayer control on my XAML page like below:

<CustomMediaElement:CustomMediaPlayer 
                x:Name="custMediaElement"  
                VerticalAlignment="Center"
                Width="600" Height="300"  Visibility="Collapsed" />

Now I am ble to set the playList by using setPlayList() method like below:

private void setPlayList()
            {
                IEnumerable eLevelData = null;
                eLevelData = pMainPage.GetDataFromDictonary(pMainPage.strChildFolderID);

                    foreach (RMSMedia folderItems in eLevelData)
                    {
                        string strmediaURL = folderItems.strMediaFileName;
                        if (hasExtension(strmediaURL) == "wmv" || hasExtension(strmediaURL) == "mp4" || hasExtension(strmediaURL) == "mp3" || hasExtension(strmediaURL) == "mpg")
                        {
                            PlaylistItem playListItem = new PlaylistItem();
                            string thumbSource = folderItems.strAlbumcoverImage;
                            playListItem.MediaSource = new Uri(strmediaURL, UriKind.RelativeOrAbsolute);

                            playListItem.Title = folderItems.strAlbumName;

                            if (!string.IsNullOrEmpty(thumbSource))

                                playListItem.ThumbSource = new Uri(thumbSource, UriKind.RelativeOrAbsolute);

                            playList.Items.Add(playListItem);
                        }
                }


                custMediaElement.Playlist = playList;

            }

Now , I want to change the PlayListIndex of Mediaplayer, when user clicks on a listBox Item , which contains the title of all the songs.

When the user clicks on the third song title from the songs Title List the mediaPlayer should play the third song , or if the user cliks on 7th song title, the mediaPlayer should play the 7th song.

My motto is to pick up the Selected index from the listbox and assign it to the PlayList Index of mediaPlayer.

While I add a watch to playList I am able to see , playList , Items , [0] PlaylistIndex 1

playList , Items , [1] PlaylistIndex 2

But While I am trying to set it from the code , the same property PlaylistIndex seems unavailable. Please help.

Thanks, Subhen

1条回答
放荡不羁爱自由
2楼-- · 2019-08-27 18:22

It was not that complicated. I was just unsure of the methods. So answer goes like below:

int currentPlayListItem = listBox.SelectedIndex;
custMediaElement.GoToPlaylistItem(currentPlayListItem);
查看更多
登录 后发表回答