java - 使用 COM 和 Java 在 iTunes 中创建播放列表

标签 java com itunes jacob

如何使用 COM(在 Windows 上,即没有 AppleScript)从 Java 在 iTunes 中创建播放列表?

我找到了一个图书馆 here这完成了我需要的大部分工作,并且我向 ITPlaylist.java 添加了一些代码,以调用 iTunes 对象 ITPlaylist 上的“AddTrack”方法(提到 in the docs):

 public void addTrack(ITTrack track) {
    ITPlaylistKind k = getKind();
    if (k == ITPlaylistKindUser) {
        Dispatch.put(object, "AddTrack", track);
    } else
        throw new UnsupportedOperationException("can only add track to user playlists - kind : " + k);
}

但是我得到一个错误:

# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x1000e150, pid=3184, tid=3896
#
# JRE version: 6.0_15-b03
# Java VM: Java HotSpot(TM) Client VM (14.1-b02 mixed mode, sharing windows-x86)
# Problematic frame:
# C [jacob-1.14.3-x86.dll+0xe150]
#
# An error report file with more information is saved as:
# Z:\\hs_err_pid3184.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

当我尝试调用此方法时。日志文件包含:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x1000e150, pid=3040, tid=3756
#
# JRE version: 6.0_15-b03
# Java VM: Java HotSpot(TM) Client VM (14.1-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [jacob-1.14.3-x86.dll+0xe150]
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

Current thread (0x01ed1400):  JavaThread "main" [_thread_in_native, id=3756, stack(0x003b0000,0x00400000)]

siginfo: ExceptionCode=0xc0000005, reading address 0x00000005

Registers:
EAX=0x00000000, EBX=0x0490f6f8, ECX=0x003ffd8c, EDX=0x240b14e8
ESP=0x003ff9d0, EBP=0x003ffa14, ESI=0x01ed1510, EDI=0x00000005
EIP=0x1000e150, EFLAGS=0x00010246

Top of Stack: (sp=0x003ff9d0)
0x003ff9d0:   01ed1400 28404d90 28404d90 01fd9e27
0x003ff9e0:   01ed1510 003ffa28 003ffa24 01ed1400
0x003ff9f0:   2840bbaf 003ff9f4 00000000 003ffa28
0x003ffa00:   28409fb8 00000000 28404d90 00000000
0x003ffa10:   003ffa24 003ffa4c 01fd2da1 00000000
0x003ffa20:   01fd8259 240b14e8 240b39d8 003ffa2c
0x003ffa30:   2840401a 003ffa58 28409fb8 00000000
0x003ffa40:   28404040 003ffa24 003ffa54 003ffa7c 

Instructions: (pc=0x1000e150)
0x1000e140:   1d 53 ff 15 20 01 01 10 66 c7 03 09 00 89 7b 08
0x1000e150:   8b 0f 8b 51 04 57 ff d2 5f 5e 5b c2 0c 00 6a ff 


Stack: [0x003b0000,0x00400000],  sp=0x003ff9d0,  free space=318k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [jacob-1.14.3-x86.dll+0xe150]
j  com.jacob.com.Variant.putObject(Ljava/lang/Object;)V+2
j  com.jacob.com.VariantUtilities.populateVariant(Lcom/jacob/com/Variant;Ljava/lang/Object;Z)V+511
j  com.jacob.com.VariantUtilities.objectToVariant(Ljava/lang/Object;)Lcom/jacob/com/Variant;+248
j  com.jacob.com.VariantUtilities.objectsToVariants([Ljava/lang/Object;)[Lcom/jacob/com/Variant;+19
j  com.jacob.com.Dispatch.invoke(Lcom/jacob/com/Dispatch;Ljava/lang/String;I[Ljava/lang/Object;[I)Lcom/jacob/com/Variant;+8
j  com.jacob.com.Dispatch.put(Lcom/jacob/com/Dispatch;Ljava/lang/String;Ljava/lang/Object;)V+18
j  com.dt.iTunesController.ITPlaylist.addTrack(Lcom/dt/iTunesController/ITTrack;)V+19
j  uk.co.teamnomad.itunes.WindowsLibraryImpl.savePlaylist(Ljava/util/List;Luk/co/teamnomad/itunes/PlayList;)V+46
j  uk.co.teamnomad.bpm.main.Main.<init>(Luk/co/teamnomad/bpm/system/OperatingSystem;)V+309
j  uk.co.teamnomad.bpm.main.Main.getInstance()Luk/co/teamnomad/bpm/main/Main;+16
j  uk.co.teamnomad.bpm.main.Main.main([Ljava/lang/String;)V+8
v  ~StubRoutines::call_stub
V  [jvm.dll+0xecfac]
V  [jvm.dll+0x1741d1]
V  [jvm.dll+0xed02d]
V  [jvm.dll+0xf5bf5]
V  [jvm.dll+0xfd84d]
C  [java.exe+0x2155]
C  [java.exe+0x82ce]
C  [kernel32.dll+0x44911]
C  [ntdll.dll+0x3e4b6]
C  [ntdll.dll+0x3e489]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  com.jacob.com.Variant.putVariantDispatch(Ljava/lang/Object;)V+0
j  com.jacob.com.Variant.putObject(Ljava/lang/Object;)V+2
j  com.jacob.com.VariantUtilities.populateVariant(Lcom/jacob/com/Variant;Ljava/lang/Object;Z)V+511
j  com.jacob.com.VariantUtilities.objectToVariant(Ljava/lang/Object;)Lcom/jacob/com/Variant;+248
j  com.jacob.com.VariantUtilities.objectsToVariants([Ljava/lang/Object;)[Lcom/jacob/com/Variant;+19
j  com.jacob.com.Dispatch.invoke(Lcom/jacob/com/Dispatch;Ljava/lang/String;I[Ljava/lang/Object;[I)Lcom/jacob/com/Variant;+8
j  com.jacob.com.Dispatch.put(Lcom/jacob/com/Dispatch;Ljava/lang/String;Ljava/lang/Object;)V+18
j  com.dt.iTunesController.ITPlaylist.addTrack(Lcom/dt/iTunesController/ITTrack;)V+19
j  uk.co.teamnomad.itunes.WindowsLibraryImpl.savePlaylist(Ljava/util/List;Luk/co/teamnomad/itunes/PlayList;)V+46
j  uk.co.teamnomad.bpm.main.Main.<init>(Luk/co/teamnomad/bpm/system/OperatingSystem;)V+309
j  uk.co.teamnomad.bpm.main.Main.getInstance()Luk/co/teamnomad/bpm/main/Main;+16
j  uk.co.teamnomad.bpm.main.Main.main([Ljava/lang/String;)V+8
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x043a4800 JavaThread "MerapiBridgeSocket" [_thread_in_native, id=3664, stack(0x04800000,0x04850000)]
  0x01f4c800 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=2440, stack(0x04160000,0x041b0000)]
  0x01f47c00 JavaThread "CompilerThread0" daemon [_thread_blocked, id=3628, stack(0x04110000,0x04160000)]
  0x01f47400 JavaThread "Attach Listener" daemon [_thread_blocked, id=3584, stack(0x040c0000,0x04110000)]
  0x01f3ac00 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=2968, stack(0x04070000,0x040c0000)]
  0x01ef8c00 JavaThread "Finalizer" daemon [_thread_blocked, id=3724, stack(0x04020000,0x04070000)]
  0x01ef7800 JavaThread "Reference Handler" daemon [_thread_blocked, id=3324, stack(0x03fd0000,0x04020000)]
=>0x01ed1400 JavaThread "main" [_thread_in_native, id=3756, stack(0x003b0000,0x00400000)]

Other Threads:
  0x01ef6000 VMThread [stack: 0x01180000,0x011d0000] [id=2836]
  0x01f5f000 WatcherThread [stack: 0x041b0000,0x04200000] [id=3528]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
 def new generation   total 960K, used 794K [0x24000000, 0x24100000, 0x244e0000)
  eden space 896K,  81% used [0x24000000, 0x240b7510, 0x240e0000)
  from space 64K,  95% used [0x240f0000, 0x240ff450, 0x24100000)
  to   space 64K,   0% used [0x240e0000, 0x240e0000, 0x240f0000)
 tenured generation   total 4096K, used 876K [0x244e0000, 0x248e0000, 0x28000000)
   the space 4096K,  21% used [0x244e0000, 0x245bb318, 0x245bb400, 0x248e0000)
 compacting perm gen  total 12288K, used 4255K [0x28000000, 0x28c00000, 0x2c000000)
   the space 12288K,  34% used [0x28000000, 0x28427cb8, 0x28427e00, 0x28c00000)
    ro space 8192K,  63% used [0x2c000000, 0x2c519920, 0x2c519a00, 0x2c800000)
    rw space 12288K,  53% used [0x2c800000, 0x2ce74dd0, 0x2ce74e00, 0x2d400000)

Dynamic libraries:
0x00400000 - 0x00424000     C:\Windows\system32\java.exe
0x771a0000 - 0x772c7000     C:\Windows\system32\ntdll.dll
0x75a20000 - 0x75afb000     C:\Windows\system32\kernel32.dll
0x75ee0000 - 0x75fa6000     C:\Windows\system32\ADVAPI32.dll
0x772e0000 - 0x773a3000     C:\Windows\system32\RPCRT4.dll
0x7c340000 - 0x7c396000     C:\Program Files\Java\jre6\bin\msvcr71.dll
0x6d800000 - 0x6da8b000     C:\Program Files\Java\jre6\bin\client\jvm.dll
0x77060000 - 0x770fd000     C:\Windows\system32\USER32.dll
0x773b0000 - 0x773fb000     C:\Windows\system32\GDI32.dll
0x744f0000 - 0x74522000     C:\Windows\system32\WINMM.dll
0x76f30000 - 0x76fda000     C:\Windows\system32\msvcrt.dll
0x76d20000 - 0x76e64000     C:\Windows\system32\ole32.dll
0x75d20000 - 0x75dad000     C:\Windows\system32\OLEAUT32.dll
0x744b0000 - 0x744e9000     C:\Windows\system32\OLEACC.dll
0x77100000 - 0x7711e000     C:\Windows\system32\IMM32.DLL
0x76c00000 - 0x76cc8000     C:\Windows\system32\MSCTF.dll
0x75820000 - 0x7584c000     C:\Windows\system32\apphelp.dll
0x772d0000 - 0x772d9000     C:\Windows\system32\LPK.DLL
0x77120000 - 0x7719d000     C:\Windows\system32\USP10.dll
0x6d7b0000 - 0x6d7bc000     C:\Program Files\Java\jre6\bin\verify.dll
0x6d330000 - 0x6d34f000     C:\Program Files\Java\jre6\bin\java.dll
0x6d290000 - 0x6d298000     C:\Program Files\Java\jre6\bin\hpi.dll
0x75a10000 - 0x75a17000     C:\Windows\system32\PSAPI.DLL
0x6d7f0000 - 0x6d7ff000     C:\Program Files\Java\jre6\bin\zip.dll
0x6d610000 - 0x6d623000     C:\Program Files\Java\jre6\bin\net.dll
0x76e70000 - 0x76e9d000     C:\Windows\system32\WS2_32.dll
0x75fb0000 - 0x75fb6000     C:\Windows\system32\NSI.dll
0x75030000 - 0x7506b000     C:\Windows\system32\mswsock.dll
0x75090000 - 0x75095000     C:\Windows\System32\wship6.dll
0x74cf0000 - 0x74cf5000     C:\Windows\System32\wshtcpip.dll
0x10000000 - 0x10019000     C:\Windows\System32\jacob-1.14.3-x86.dll
0x72640000 - 0x726db000     C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.1434_none_d08b6002442c891f\MSVCR80.dll
0x76ea0000 - 0x76f24000     C:\Windows\system32\CLBCatQ.DLL
0x74db0000 - 0x74deb000     C:\Windows\system32\rsaenh.dll

VM Arguments:
java_command: bpm-0.0.13-jar-with-dependencies.jar
Launcher Type: SUN_STANDARD

Environment Variables:
CLASSPATH=.;C:\Program Files\QuickTime\QTSystem\QTJava.zip
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\QuickTime\QTSystem\
USERNAME=ed
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 6, GenuineIntel



---------------  S Y S T E M  ---------------

OS: Windows Vista Build 6001 Service Pack 1

CPU:total 1 (2 cores per cpu, 1 threads per core) family 6 model 23 stepping 6, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1

Memory: 4k page, physical 2097151k(1656488k free), swap 4194303k(4092420k free)

vm_info: Java HotSpot(TM) Client VM (14.1-b02) for windows-x86 JRE (1.6.0_15-b03), built on Jul 25 2009 01:22:46 by "java_re" with MS VC++ 7.1

time: Mon Aug 31 20:14:48 2009
elapsed time: 7 seconds

我做错了什么?

最佳答案

我已经有一段时间没有用 Java 完成任何 iTunes 的工作了,但根据我的经验,我记得界面可能相当多变。

我没有任何明确的答案,但为了至少在黑暗中提供一个镜头,也许你应该尝试将你正在使用的 ITPlaylist 转换为 ITUserPlaylist(当然,如果这是正确的类型)然后调用它的 addTrack 方法。这样您就可以使用库提供的功能,如果这不起作用,您可以与开发人员联系,因为可能会出现更严重的问题。

从您提供的转储来看,JACOB 中的底层 C 似乎正在尝试通过 iTunes COM 接口(interface)修改等效的 ITPlaylist。这可能是因为继承的工作方式? IE:ITPlaylist 不支持 addTrack(底层 C 试图调用一个不存在的函数)但 ITUserPlaylist 支持吗?只是一个想法。

建议的更正:

public void addTrack(ITTrack track) {
    ITPlaylistKind k = getKind();
    if (k == ITPlaylistKindUser) {
        Dispatch.put( ((ITUserPlaylist)this).object, "AddTrack", track);
    } else
        throw new UnsupportedOperationException("can only add track to user playlists - kind : " + k);
}

再说一次,我当然不是这里的专家,所以如果有人有更好的想法,请继续发帖给我 :)

让我知道这是否能为您带来任何成功!

编辑 重新阅读我的帖子后,我意识到我忘记了这种方法,这种方法可以说是更好的方法,因为它使 JACOB COM 桥远离更高级别的东西:

((ITUserPlaylist)this).addTrack(track);

关于java - 使用 COM 和 Java 在 iTunes 中创建播放列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1358449/

相关文章:

java - 使用gmail API添加gmail签名

java - 使用java提取*.b64文件

java - jaxb、xsd 替换复杂类型

c++ - COM 中的 Release() 函数

iphone - 提交之前,iPhone应用程序商店链接不起作用

ios - 禁用在 iTunes 文件共享中添加文件

ios - 测试应用内购买,无需在 iTunes 中提交应用且未验证产品

java - putExtra() 不起作用

c# - 没有动态关键字的智能感知?

javascript - 是否可以提供 JavaScript API 来控制 USB、LPT 和 COM 设备?