如何为Mediaplayer(ExpressionMediaPlayer:Mediaplayer)设置播放列表索引 [英] How to set the PlayList Index for Mediaplayer(ExpressionMediaPlayer:Mediaplayer)

查看:106
本文介绍了如何为Mediaplayer(ExpressionMediaPlayer:Mediaplayer)设置播放列表索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的XAML页面上有一个Mediaplayer控件,如下所示:

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

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

现在,我可以使用如下所示的setPlayList()方法来设置播放列表:

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;

            }

现在,当用户单击包含所有歌曲标题的listBox Item时,我想更改Mediaplayer的PlayListIndex.

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

当用户单击歌曲标题列表"中的第三首歌曲标题时,mediaPlayer应该播放第三首歌曲,或者如果用户单击第七首歌曲标题,那么mediaPlayer应该播放第七首歌曲.

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.

我的座右铭是从列表框中选择选定"索引,并将其分配给mediaPlayer的播放列表"索引.

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

当我在playList中添加手表时,我可以看到playListItems[0] PlaylistIndex 1

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

playListItems[1] PlaylistIndex 2

但是当我尝试从代码中设置它时,相同的属性PlaylistIndex似乎不可用.请帮忙.

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

谢谢, 苏本

推荐答案

没有那么复杂.我只是不确定这些方法.因此答案如下:

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

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

这篇关于如何为Mediaplayer(ExpressionMediaPlayer:Mediaplayer)设置播放列表索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆