Click here to Skip to main content
15,909,091 members
Articles / Programming Languages / Visual Basic
Article

iTunes Control Using VB.NET

Rate me:
Please Sign up or sign in to vote.
3.44/5 (8 votes)
28 Nov 2006CPOL2 min read 129.1K   1.7K   38   39
Exploring the iTunes interface using VB.

Image 1

Introduction

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.

Background

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

History

Updated version. Added Try blocks for the iTunes application.

License

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


Written By
Retired
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Playing specific songs Pin
JoeRip10-Nov-07 18:13
JoeRip10-Nov-07 18:13 
Actually, no matter if the two libraries are the same, this will NOT work.

The ID's you list here are runtime, session specific - they exist only for the session that iTunes is running. They are different each time iTunes loads its library.

There is an invariant, persistent identifier for a track, but it exists only in the XML library itself, and it's not available through the COM API, neither for reading or executing, so it's not going to help you.

If the files have exact same path of both computers, or if both paths are known to you, you could use PlayFile:

HRESULT IiTunes::PlayFile ( [in] BSTR filePath )

Play the specified file path, adding it to the library if not already present.


Parameters:
filePath Full path to the file to be played.

Return values:
S_OK The operation was successful.
E_POINTER filePath is NULL.
E_INVALIDARG filePath is invalid.
E_FAIL An unexpected error occurred.

If not, there's also a Find API where you specify a Source (Library, Playlist, etc) and some song specifics. If you know something unique about both songs (ie, if the search is only going to return one song on each computer), you could use that. You'll need to do some work, though. First, you need to get the iTunes COM SDK and read the documentation Smile | :) .
Generalnice Pin
Tollyver9-Apr-07 21:25
Tollyver9-Apr-07 21:25 
GeneralRe: nice Pin
Michael_Davies13-Apr-07 3:42
Michael_Davies13-Apr-07 3:42 
GeneralNice! Pin
Leonardo Paneque29-Nov-06 15:55
Leonardo Paneque29-Nov-06 15:55 
GeneralRe: Nice! Pin
crossreferance3-Feb-07 0:35
crossreferance3-Feb-07 0:35 
GeneralRe: Nice! Pin
Michael_Davies13-Apr-07 3:39
Michael_Davies13-Apr-07 3:39 
GeneralITDETECTORLib Pin
sheepy89826-Nov-06 8:38
sheepy89826-Nov-06 8:38 
GeneralRe: ITDETECTORLib [modified] Pin
Michael_Davies26-Nov-06 21:44
Michael_Davies26-Nov-06 21:44 
GeneralRe: ITDETECTORLib Pin
sheepy89817-Dec-06 18:17
sheepy89817-Dec-06 18:17 
GeneralRe: ITDETECTORLib Pin
Michael_Davies17-Dec-06 21:25
Michael_Davies17-Dec-06 21:25 
GeneralNullRef Pin
chrisr021-Nov-06 13:50
chrisr021-Nov-06 13:50 
GeneralRe: NullRef Pin
Michael_Davies21-Nov-06 21:57
Michael_Davies21-Nov-06 21:57 
GeneralMotivation Pin
SilimSayo10-Nov-06 7:59
SilimSayo10-Nov-06 7:59 
GeneralRe: Motivation Pin
Michael_Davies10-Nov-06 21:58
Michael_Davies10-Nov-06 21:58 

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

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