How to set the PlayList Index for Mediaplayer(ExpressionMediaPlayer:Mediaplayer)

烈酒焚心 提交于 2019-12-13 03:23:59

问题


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:


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

int currentPlayListItem = listBox.SelectedIndex;
custMediaElement.GoToPlaylistItem(currentPlayListItem);


来源:https://stackoverflow.com/questions/2780295/how-to-set-the-playlist-index-for-mediaplayerexpressionmediaplayermediaplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!