Null reference exception While Navigating to PlayListItem.

Posted by Subhen on Stack Overflow See other posts from Stack Overflow or by Subhen
Published on 2010-05-20T11:51:33Z Indexed on 2010/05/20 12:00 UTC
Read the original article Hit count: 357

Filed under:
|
|

Hi,

I am trying to play the selected media from PlayList,if the selected index is not zero as below:

if (playList.Items.Count == 0)
   {
      setPlayList();
          if (selectedIndex!= 0)
               { 
                  if(custMediaElement.Playlist!=null)
                  custMediaElement.GoToPlaylistItem(selectedIndex);
               }
    }

The setPlayLIst method is as below:

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

            foreach (RMSMedia folderItems in eLevelData)
            {
                string strmediaURL = folderItems.strMediaFileName;
                string strmediaExtension = GetExtension(strmediaURL);
                if (strmediaExtension == "wmv" || strmediaExtension == "mp4" || strmediaExtension == "mp3" || strmediaExtension == "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;
        }

But I am getting a Null reference Exception while trying to go to PlayList Item with the help of selected index , as explained in top. This works fine if I don't use custMediaElement.GoToPlaylistItem(selectedIndex); but in that case the Media Player Always plays the 1st Item , No matter , Which ever Song I select from the List Box.

Below is few details from Stack Trace:

ExpressionMediaPlayer.MediaPlayer.DoOpenPlaylistItem(PlaylistItem playlistItem)
at ExpressionMediaPlayer.MediaPlayer.GoToPlaylistItem(Int32 playlistItemIndex)

Thanks,

Subhen

© Stack Overflow or respective owner

Related posts about silverlight-3.0

Related posts about wpf