Click here to Skip to main content
13,288,520 members (59,944 online)
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 14 Jul 2004

Controlling iTunes through COM

, 14 Jul 2004
Rate this:
Please Sign up or sign in to vote.
An example of how to utilize COM in C# through a system tray application that controls iTunes


Apple's iTunes is a powerful audio library manager and player now available for both Windows and Mac. Its feature set is endless and expanding, and, thankfully, through COM, third-party developers can access a good portion of this, even through the .NET Framework and its interop capabilities.

I have built a simple demo application to demonstrate a variety of the features that are available using the iTunes COM interface. This application, by no means, represents the full power of the interface, but is designed to show the different capabilities. Apple's developer web site has an SDK for the complete COM interface.

My application is a system tray utility for controlling iTunes easily and displaying the currently play track. It calls methods, changes properties, and receives events all through COM. It implements the basic functionality of playing, pausing, stopping and changing the currently playing track as well as popping up a window when the track changes.

Instantiating the iTunes Application

In order to access the features that iTunes has to offer, you must first add a reference to the iTunes COM Library to your project. Right click on your project in the Solution Explorer, choose "Add Reference...". Select the COM tab and find the "iTunes 1.1 Type Library", click "Select" and finally click "OK". You will now see "iTunesLib" under your References list for that project.

Next, in any files that you want to communicate with iTunes in, add the following directive:

using iTunesLib;

In order to control iTunes you must create a new instance if the controlling interface. This interface allows your program to communicate with and control (and be controlled by) and already open instance of iTunes.

private myiTunes = new iTunesAppClass();

Using this myiTunes member, you can access functions like Play(), Pause(), Stop(), and Quit(). If for some reason iTunes is closed and your application continues to try and communicate with it, a COMException will be thrown.

Receiving Events from iTunes

The myiTunes member also allows access to certain events like when a new track starts playing, when the current one stops, etc. To specify a new event handler for one of these events, iTunesLib uses the same delegate model that all other events in C# use:

// Add Event Handler
myiTunes.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(

// Event Handler
protected void myiTunes_OnPlayerPlayEvent(object iTrack)

The iTrack parameter provides information about the currently playing track, but in order to get at this information, we must first cast the iTrack into an IITTrack variable.

string myArtist, myName;

IITTrack myTrack = (IITTrack) iTrack;
myArtist = myTrack.Artist;
myName = myTrack.Name;

This is by no means all of the information available in the IITTrack interface. More information is available in Apple's documentation.


I hope that I have merely whetted you appetite in terms of what can be done with controlling Apple's powerful audio application, iTunes. The possibilities are endless: you can batch convert your media to a different format, organize and manage playlists, and batch rename tracks, among other things. Consult Apple's SDK for more information. It is vague in terms of examples, however it contains information about all of the interfaces, what they do, and what members and functions are accessible through each.

Furthermore, I hope I have introduced you to the idea of COM (component object module) and its potentials within your own work. Whether utilizing other COM components functionality or creating your own COM components, I think you will find that it can be endlessly useful, under the right circumstances.

System Requirements

This software is known to work with the following configuration:

  • Microsoft Windows XP SP1 or later
  • Microsoft .NET Framework 1.1
  • Apple iTunes 4.6

The software may possibly work under different configurations, but this has not be verified to date.

Known Issues

  • AnimateWindow WinAPI function does not work properly for fading in the popup display.
  • Popup window timer does not reset when track is changed while popup is showing.


  • 07/14/2004 - Article Released


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Adam Durity
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionControl speed Pin
X3m27-Nov-17 9:36
memberX3m27-Nov-17 9:36 
QuestionItunes backup control Pin
Beniwal0125-Sep-13 1:14
memberBeniwal0125-Sep-13 1:14 
QuestionHow Do I Search The Itune Library? Pin
cworkman2972922-Jul-09 20:55
membercworkman2972922-Jul-09 20:55 
Generalstreaming track from iPod to PC Pin
Halid Niyaz23-Aug-06 6:29
memberHalid Niyaz23-Aug-06 6:29 
GeneralPopup window timer does not reset when track is changed while popup is showing. Pin
zelig26-May-06 7:49
memberzelig26-May-06 7:49 
GeneralEvent handling Pin
dark_omen23-Mar-06 14:43
memberdark_omen23-Mar-06 14:43 
AnswerRe: Event handling Pin
ndphuong16-Sep-06 22:08
memberndphuong16-Sep-06 22:08 
AnswerRe: Event handling Pin
Chiser9910-Nov-06 13:02
memberChiser9910-Nov-06 13:02 
GeneralUsing with .NET 2.0 Framework Pin
Shawn McCartt23-Jan-06 15:31
memberShawn McCartt23-Jan-06 15:31 
In order to get the Title/Artist update working correctly with VS 2005 and the .NET 2.0 Framework, I found I needed to add a line to the iTunesTray constuctor:

Label.CheckForIllegalCrossThreadCalls = false;

to prevent this new check from blocking the label text update. Just an FYI to anyone else seeing this problem.
GeneralNot working Pin
Ludo de la Pena10-Mar-06 9:15
memberLudo de la Pena10-Mar-06 9:15 
GeneralRe: Not working ? Pin
Ludo de la Pena10-Mar-06 9:44
memberLudo de la Pena10-Mar-06 9:44 
GeneralManaging multiple invocations of the COM interop Pin
Drew Noakes21-Jan-06 11:58
memberDrew Noakes21-Jan-06 11:58 
GeneralRe: Managing multiple invocations of the COM interop Pin
Member 235878828-Aug-08 4:24
memberMember 235878828-Aug-08 4:24 
GeneralRe: Managing multiple invocations of the COM interop Pin
Drew Noakes28-Aug-08 6:08
memberDrew Noakes28-Aug-08 6:08 
QuestionHide iTunes Pin
tayspen11-Nov-05 10:35
membertayspen11-Nov-05 10:35 
QuestionMusic Folder Pin
TraPpeur29-Sep-05 9:49
memberTraPpeur29-Sep-05 9:49 
AnswerRe: Music Folder Pin
Adam Durity13-Oct-05 18:53
memberAdam Durity13-Oct-05 18:53 
GeneralRe: Music Folder Pin
TraPpeur14-Oct-05 1:37
memberTraPpeur14-Oct-05 1:37 
GeneralRe: Music Folder Pin
Erikpro8-May-07 23:43
memberErikpro8-May-07 23:43 
GeneralAdding Tracks to iTunes Pin
sindhoor5-Jun-05 5:25
membersindhoor5-Jun-05 5:25 
GeneralItunes COM Events Pin
zx2c425-Mar-05 15:12
memberzx2c425-Mar-05 15:12 
AnswerRe: Itunes COM Events Pin
pVALIUM2-Nov-07 1:37
memberpVALIUM2-Nov-07 1:37 
GeneralRe: Itunes COM Events Pin
pardillojuegos2-Jul-12 5:35
memberpardillojuegos2-Jul-12 5:35 
GeneralReceiving Events from iTunes Pin
Matt Berube6-Sep-04 9:52
sussMatt Berube6-Sep-04 9:52 
GeneralRe: Receiving Events from iTunes Pin
zx2c426-Mar-05 7:26
memberzx2c426-Mar-05 7:26 
AnswerRe: Receiving Events from iTunes Pin
Matt Berube4-Dec-05 6:08
memberMatt Berube4-Dec-05 6:08 
QuestionRe: Receiving Events from iTunes Pin
slowlyhazeing25-Dec-05 11:11
memberslowlyhazeing25-Dec-05 11:11 
AnswerRe: Receiving Events from iTunes Pin
pVALIUM2-Nov-07 1:45
memberpVALIUM2-Nov-07 1:45 
GeneralMac equivalent Pin
Anonymous24-Aug-04 14:51
sussAnonymous24-Aug-04 14:51 
GeneralSo... Pin
eshipman23-Aug-04 7:53
membereshipman23-Aug-04 7:53 
GeneralRe: So... Pin
Adam Durity24-Aug-04 13:38
memberAdam Durity24-Aug-04 13:38 
GeneralRe: So... Pin
Anonymous7-Oct-04 5:26
sussAnonymous7-Oct-04 5:26 
GeneralRe: So... Pin
eshipman7-Oct-04 7:23
membereshipman7-Oct-04 7:23 
GeneralRe: So... Pin
Marcel (was anonymous)8-Oct-04 2:56
sussMarcel (was anonymous)8-Oct-04 2:56 
GeneralRe: So...(Hide window using c# Pin
quickdraw690621-Jan-07 14:17
memberquickdraw690621-Jan-07 14:17 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 15 Jul 2004
Article Copyright 2004 by Adam Durity
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid