Domanda

        //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
È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top