dot-totally.co.uk > Software > iTunes Controller
iTunes Controller
iTunes Controller is a Java wrapper package that allows you to control iTunes from your Java application. It uses the excellent JACOB Java-COM Bridge to communicate but provides all the interfaces for you to use straight away without dealing with messy COM objects, variants and dispatch calls. You can control what is playing, manage playlists and various sources (such as the main library or any connected iPod) and control nearly every aspect of the iTunes application. The design of the package and it's available functions very closely follows the original iTunes COM API specification available from Apple.
The project is a work-in-progress, and whilst most of the major functions are already included, several lesser-used functions and interfaces are currently missing from the class. These will be addressed in future releases.
Download
Version 0.2 (released 31st August 2009)
Please Note: You must import JACOB for this project to work. A link to this project's website where you can download the binary JACOB .jar files can be found at the bottom of the page.
History
| Version | Release Date | Binary .JAR | Source | JavaDocs |
| 0.2 | 2009-08-31 | Download | Download | View |
| 0.1 | 2008-10-20 | Download | Download | View |
Subversion / Project Management
Latest changes can be found in the iTunes Controller Subversion repository. Any bugs, feature requests, etc. can be submitted or followed on the Redmine project management tracker.
Documentation
All of the functions that have been implemented thus far have been fully documented using a similar fashion to the official iTunes COM SDK documentation. You can find details of all the functions in this API guide:
Examples of use
Get information about the currently playing track:
iTunes itc = new iTunes(); ITTrack itt = itc.getCurrentTrack(); System.out.println("Currently playing:"); System.out.println("Name: " + itt.getName()); System.out.println("By: " + itt.getArtist()); System.out.println("Album: " + itt.getAlbum());
Skip to the next track, wait for 5 seconds and pause:
iTunes itc = new iTunes(); itc.nextTrack(); try { Thread.sleep(5000); } catch (InterruptedException e) {} itc.playPause();
Event Handling
The iTunes Controller package does implement event handling on all but one of the
functions the iTunes COM interface provides. By creating a class that implements the
iTunesEventsInterface class, and then using iTunes.addEventHandler()
function, you can receive events from the iTunes class, such as when tracks change
or if the user pauses playback. However, iTunes will only allow one application to
receive COM events at once, and if your application doesn't release its COM Thread
iTunes will refuse any more connections until iTunes has been closed and reopened.
This is most important with using Swing, which will prevent a COM Thread from closing
when the application finishes. I will be attempting to introduce measures to combat
this, though for now you may have to use the iTunes class in a seperate thread when
using Swing interfaces.
External Sources
- JACOB Project
The JAVA-COM Bridge project that enables COM communication. - iTunes COM for
Windows SDK
Official Apple documentation for the COM SDK.