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

似乎是正确的行动方针。但是,我希望用户能够简单地指定歌曲标题......

我可以使用提示让艺术家和专辑查看要浏览的文件夹,因为这就是 iTunes 存储文件的方式......(例如 C:\Users\username\Music\iTunes\iTunes Media\Artist\Album\song )

有谁知道我可以直接进入指定歌曲的方法吗?我一直在寻找一段时间。

如果有帮助,这里是我正在使用的 API 的文档http://www.dot-totally.co.uk/software/itunescon/javadoc-0.2/index.html

更新 - - - - - - - - - - - - - - - - -

于是我起身......

//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

我被困住了.... :(

编辑:

想我可以根据从 sourcecollection 获得的信息手动创建一个轨道。虽然对构造函数感到困惑......

ITTrack(com.jacob.com.Dispatch d)

???谁能澄清创建 ITTrack 对象的正确语法是什么?这是它的javadoc,我不明白。

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

更新 - - - - - - - - - - - - - - - - - - -

好的。所以我使用了 fetchDispatch() 方法来创建一个 ITTrack 类。 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();

我现在遇到一个例外:

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 这么近!所以我在输入项目“名称”的方法上做错了......但是什么?

我想也许如果我输入:

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

查找来源的名称....但我猜它没有 toString() 方法?输出是:

com.dt.iTunesController.ITSourceCollection@118278a
4

1 回答 1

0

我最终废弃了 iTunes 控制器 API 并使用 JacobGen 生成了我自己的。我发现索引 1 是库源,对于 IITPlaylistCollection,索引 1 是库播放列表(所有歌曲),然后在 IITTrack 对象上调用 play()。工作得很好,如果它还没有打开,甚至可以打开 iTunes!

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();

与播放列表类似:

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();

感谢您的所有指点,希望这可以帮助任何有类似问题的人。我花了很长时间才弄清楚如何让 JacobGen 工作,因为互联网上几乎没有任何文档。如果有人有任何问题,我很乐意就此发表一篇文章。

于 2013-04-12T20:27:35.637 回答