Long have I searched for an article on using iTunes through VB; there are many examples in C flavours, even Java, but few using VB. The iTunes SDK details what is available, but has little on usage.
iTunes is a wonderful player, relatively uncomplicated in its use, no adverts or unnecessary gadget like interfaces. I had several reasons for exploring the use of my own interface to it main one being I have an iPod, and want to get information off it and back to the PC. The drive for writing this code was the annoying habit iTunes has of drag and drop of playlists, fine if you are using a mouse as you have to hold down the mouse but I was writing an application that uses a touch screen and drag and drop plays havoc with the playlists. As a result the playlists and tracklists on the form of this application are quite large to make nice landing zones for fingers.
Using the code
You do not need the iTunes SDK to access iTunes, it just helps to start to locate what you want, though I have found that some features are not exposed in the IDE. Also, some of the types do not expose either, which is frustrating as you have to remember to press Escape to prevent the nearest name, usually a collection of the same type, being filled in by the IDE. For example, typing
Dim objPlayList as iTunesLib.IITPlayList will produce
Dim objPlayList as iTunesLib.IITPlayListCollection, as
IITPlayList is not exposed.
To use the code, you must have iTunes installed and add a reference to your project of the COM interface "iTunes x.x Type Library" where x.x is the version installed with the iTunes version; mine was version 1.8 with version 188.8.131.52 of iTunes, and the COM interface ITDetector.
One item I can not get to work is the iTunes events, running it through the debugger shows that the event subroutines get fired but do not entirely execute for some reason; complete mystery, and if anyone solves, it I would be interested.
Points of Interest
Whilst I enjoyed solving the problem, the lack of documentation and very few examples I could find on the subject for VB did make it frustrating, which is why I decided to share this code. Good Luck.
Updated version. Added
Try blocks for the iTunes application.