Click here to Skip to main content
11,705,453 members (61,708 online)
Click here to Skip to main content

iTunes Control Using VB.NET

, 28 Nov 2006 CPOL 90.7K 1.2K 38
Rate this:
Please Sign up or sign in to vote.
Exploring the iTunes interface using VB.


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 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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionEditing Pin
Member 880234412-Apr-12 8:54
memberMember 880234412-Apr-12 8:54 
AnswerRe: Editing Pin
samyeling12-Apr-12 9:08
membersamyeling12-Apr-12 9:08 
GeneralInterop.iTunesLib.dll Pin
sumedhaswamy2-Sep-10 15:39
membersumedhaswamy2-Sep-10 15:39 
GeneralRe: Interop.iTunesLib.dll Pin
Michael_Davies2-Sep-10 21:34
memberMichael_Davies2-Sep-10 21:34 
GeneralGetting the Track Name to update itself Pin
I, the Deceiver27-Aug-10 20:09
memberI, the Deceiver27-Aug-10 20:09 
GeneralListing all songs Pin
ehrenberg15-Jun-10 12:05
memberehrenberg15-Jun-10 12:05 
GeneralRe: Listing all songs Pin
Michael_Davies16-Jun-10 8:01
memberMichael_Davies16-Jun-10 8:01 
Here is a block of code that will do it for you. The order the tracks enumerate in appears to be either backwards or random so you need to sort any lists to make them sensible.

The code uses IITTrack (had to stop visual studio from selecting IITTrackCollection by default as IITTrack is not available but it is a valid type). You do not have to use IITTrack you can do it long hand as AllTracks.Item(i).{paramtername} instead if you want, just simplifies and makes readable.

This will get you started but i will play with it a bit more as not sure this strictly answers the question because it accesses tracks on libraryplaylists, my library is over 7000 tracks and all are on playlists need to know if a track is not on a list will it appear in this list - takes so long to load... maybe you can have a go and share.

Dim AllTracks As IITTrackCollection = iTunesApp.LibraryPlaylist.Tracks
Dim aTrack As IITTrack

For i = 1 To AllTracks.Count
aTrack = AllTracks.Item(i)

' Put your code here us aTrack.Name etc. to get track paramters

GeneralRe: Listing all songs Pin
ehrenberg17-Jun-10 6:22
memberehrenberg17-Jun-10 6:22 
GeneralMy vote of 2 Pin
Dave Kreskowiak28-Aug-09 18:17
mvpDave Kreskowiak28-Aug-09 18:17 
GeneralRe: My vote of 2 Pin
Michael_Davies16-Jun-10 7:54
memberMichael_Davies16-Jun-10 7:54 
GeneralClosing iTunes Window Pin
svalerio4-Jun-08 4:00
membersvalerio4-Jun-08 4:00 
GeneralRe: Closing iTunes Window Pin
Michael_Davies4-Jun-08 23:39
memberMichael_Davies4-Jun-08 23:39 
GeneralRe: Closing iTunes Window Pin
Michael_Davies4-Jun-08 23:54
memberMichael_Davies4-Jun-08 23:54 
QuestionPlaying specific songs Pin
pftburger8-Oct-07 11:55
memberpftburger8-Oct-07 11:55 
AnswerRe: Playing specific songs Pin
Michael_Davies9-Oct-07 3:18
memberMichael_Davies9-Oct-07 3:18 
GeneralRe: Playing specific songs Pin
pftburger9-Oct-07 3:31
memberpftburger9-Oct-07 3:31 
GeneralRe: Playing specific songs Pin
JoeRip10-Nov-07 18:13
memberJoeRip10-Nov-07 18:13 
Generalnice Pin
Tollyver9-Apr-07 21:25
memberTollyver9-Apr-07 21:25 
GeneralRe: nice Pin
Michael_Davies13-Apr-07 3:42
memberMichael_Davies13-Apr-07 3:42 
GeneralNice! Pin
Leonardo Paneque29-Nov-06 15:55
memberLeonardo Paneque29-Nov-06 15:55 
GeneralRe: Nice! Pin
crossreferance3-Feb-07 0:35
membercrossreferance3-Feb-07 0:35 
GeneralRe: Nice! Pin
Michael_Davies13-Apr-07 3:39
memberMichael_Davies13-Apr-07 3:39 
sheepy89826-Nov-06 8:38
membersheepy89826-Nov-06 8:38 
GeneralRe: ITDETECTORLib [modified] Pin
Michael_Davies26-Nov-06 21:44
memberMichael_Davies26-Nov-06 21:44 
GeneralRe: ITDETECTORLib Pin
sheepy89817-Dec-06 18:17
membersheepy89817-Dec-06 18:17 
GeneralRe: ITDETECTORLib Pin
Michael_Davies17-Dec-06 21:25
memberMichael_Davies17-Dec-06 21:25 
GeneralNullRef Pin
chrisr021-Nov-06 13:50
memberchrisr021-Nov-06 13:50 
GeneralRe: NullRef Pin
Michael_Davies21-Nov-06 21:57
memberMichael_Davies21-Nov-06 21:57 
GeneralMotivation Pin
SilimSayo10-Nov-06 7:59
memberSilimSayo10-Nov-06 7:59 
GeneralRe: Motivation Pin
Michael_Davies10-Nov-06 21:58
memberMichael_Davies10-Nov-06 21:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 28 Nov 2006
Article Copyright 2006 by Michael_Davies
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid