Friday, July 10, 2009

Display iTunes Playlists in the listbox

In the previous post I described how the playlists in an iTunes library are read from the XML file and then added to the listbox.

In order for the listbox to properly display these objects, the ToString() member for each of these playlist objects is called. Here’s this method:

public override string ToString()
{
  return name() + " (ID: " + id() + ", " + getCount() + " titles)";
}
Basically, it just constructs a string that gives out some information about the playlist. Each of these pieces of information is a simple method that retrieves the required information from the part of the playlist from the XML similar to these examples:
public string id()
{
  return (string)((from element in _root.Descendants()
                   where element.Value.Equals("Playlist ID")
                   select element).First().NextNode as XElement);
}

public int getCount()
{
  return (from element in _root.Descendants()
          where element.Value.Equals("Track ID")
          select element).Count();
}
Each of these queries is quite simple once you have a look at the structure of the XML, but the combination is pretty powerful to display all the playlists in my iTunes library: image

The next post describes how the conversion of the playlists works. Main | Next

No comments:

Post a Comment