Wednesday, February 23, 2011

Look for Titles in iTunes

After I showed in the previous post how to traverse the library of iTunes, I now want to show a possibility to search specific titles. For that we traverse as described the library or specific playlists and check, if our search criteria are met.
The function shown below looks for artist and title and then returns the desired track. In the case of a complete search of course multiple results can be found, a list might be a good solution for that.

private IITTrack Suche(iTunesApp iTunesPlayer, string artist, string title)
    foreach (IITTrack track in iTunesPlayer.LibraryPlaylist.Tracks)
        if (track.Artist == artist && track.Name == title)
            return track;
    return null;

The search function could be included as follows, the following lines of code search for the song "Saturday" by "Basshunter" and then play it:

IITTrack Ergebnis = Suche(iTunesPlayer, "Basshunter""Saturday");
if (Ergebnis != null)

No comments:

Post a Comment