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