0
        //Using iTunes Controller
        iTunes itc = new iTunes();
        itc.playFile(filePath); // Takes type String

Seems like the right course of action. However, I want the user to be able to specify simply the song title...

I could use a prompt to get the Artist and Album to see what folders to browse to, since that's how iTunes stores its files ...(e.g. C:\Users\username\Music\iTunes\iTunes Media\Artist\Album\song)

Does anyone know a way I can just go straight to the specified song? I've been searching for a while.

Here are the docs for the API I'm using if that helps http://www.dot-totally.co.uk/software/itunescon/javadoc-0.2/index.html

UPDATE----------------------------------

So I got up to....

//Using iTunes Controller -- Still doesn't work
iTunes itc = new iTunes();
ITSourceCollection sc = (ITSourceCollection) itc.getSources();
ITSource source = sc.getItemByName(song);
int trackID = source.getTrackID();
// Now what to do with the track id? Look for getTrack by ID, then track.play();
// Found that a TrackCollection can return a Track by ID.
// Need to find out how to get the TrackCollection of the library

I'm stuck.... :(

EDIT:

Figured I could just manually create a track based on the info I can get from the sourcecollection. Confused about the constructor though...

ITTrack(com.jacob.com.Dispatch d)

???? Can anyone clarify what the correct syntax would be to create an ITTrack object? here is the javadoc for it, I don't understand it.

http://www.dot-totally.co.uk/software/itunescon/javadoc-0.2/com/dt/iTunesController/ITTrack.html

UPDATE--------------------------------------

Ok. So I used the fetchDispatch() method to create an ITTrack class. http://www.dot-totally.co.uk/software/itunescon/javadoc-0.2/com/dt/iTunesController/ITObject.html#fetchDispatch()

//Using iTunes Controller -- work in progress
iTunes itc = new iTunes();
ITSourceCollection libsource = (ITSourceCollection) itc.getSources();
ITSource trackToPlay = libsource.getItemByName(song);
ITTrack track = new ITTrack(trackToPlay.fetchDispatch());
track.play();

I'm now getting an exception:

Exception in thread "main" java.lang.NoSuchMethodError: com.jacob.com.Dispatch.call(Lcom/jacob/com/Dispatch;Ljava/lang/String;Ljava/lang/Object;)Lcom/jacob/com/Variant;
at com.dt.iTunesController.ITSourceCollection.getItemByName(ITSourceCollection.java:49)
at Build.Clapper3.process(-----.java:117)
at Build.Clapper3.main(-----.java:232)

gahhh so close! So I'm doing something wrong with my method of entry for the "name" of the item....but what?

I figured maybe if i input:

System.out.println(libsource.toString());

to find the names of the sources....but I guess it has no toString() method? the output was:

com.dt.iTunesController.ITSourceCollection@118278a
Riptyde4
  • 5,134
  • 8
  • 30
  • 57
  • I'd read the docs a little more and try a few things. Start by having a look at `iTunes#getSelectedTracks`. Eventually, when you get down to `ITrack`, it has a `play` method – MadProgrammer Apr 10 '13 at 02:41
  • getSelectedTracks just seems to return the track that is selected by the cursor left-click. The way I'm trying to set it up is the user inputs a song title, it gets stored in a string. The string is then used to specify what song to play by means of some method that I need to figure out. – Riptyde4 Apr 10 '13 at 03:07
  • Sorry, I meant `getSources` – MadProgrammer Apr 10 '13 at 03:10
  • :) Checking it out, good find! – Riptyde4 Apr 10 '13 at 03:20
  • I don't know if this could help but in the doc `Typically, an ITrack is accessed through an ITTrackCollection. You can retrieve all the tracks defined for a playlist using ITPlaylist.getTracks();` and I see that `ITSource` has `getPlaylists()` so maybe you can do something with that ? But I got no knowledge at all of this api. – Marc-Andre Apr 10 '13 at 04:23
  • That would work but I have no playlists defined and then I'm back to my original problem (no way to get a TrackCollection) :/ I appreciate the thought though – Riptyde4 Apr 10 '13 at 04:44
  • If anyone has any experience with using jacob I'm sure they could tell me how to get a "Dispatch d" to satisfy the constructor...then I'd be able to take it from there since I can already get all the information i need to create a ITTrack object to call the play() method on. – Riptyde4 Apr 10 '13 at 04:46
  • updated again, used fetchDispatch() method but got an exception – Riptyde4 Apr 10 '13 at 04:58

1 Answers1

0

I ended up scrapping the iTunes Controller API and generating my own with JacobGen. I figured out that index 1 is the library source & for IITPlaylistCollection, index 1 is the library playlist (all songs), then called play() on the IITTrack object. Worked beautifully, even opens iTunes if its not already open!

ActiveXComponent iTunesCom = new ActiveXComponent("iTunes.Application");
Dispatch iTunesController = new Dispatch(iTunesCom.getObject());
IiTunes it = new IiTunes(iTunesController);
IITSourceCollection sourceList = it.getSources();
IITSource s = sourceList.getItem(1); // Index 1 is library source
IITPlaylistCollection pc = s.getPlaylists();
IITPlaylist p = pc.getItem(1); // Index 1 is library playlist
IITTrackCollection tracks = p.getTracks();
IITTrack track = tracks.getItemByName(songName);
track.play();

Works similarly with playlists:

ActiveXComponent iTunesCom = new ActiveXComponent("iTunes.Application");
Dispatch iTunesController = new Dispatch(iTunesCom.getObject());
IiTunes it = new IiTunes(iTunesController);
IITSourceCollection sourceList = it.getSources();
IITSource s = sourceList.getItem(1); // Index 1 is library source
IITPlaylistCollection pc = s.getPlaylists();
IITPlaylist playlist = pc.getItemByName(playlistName);
playlist.playFirstTrack();

Thanks for all your pointers all, hopefully this helps anyone with a similar question. It took me forever to figure out how to get JacobGen working since theres barely any documentation on it anywhere on the internet. If anyone has questions I'd be glad to make a post about it.

Riptyde4
  • 5,134
  • 8
  • 30
  • 57