代码之家  ›  专栏  ›  技术社区  ›  l0st3d

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

  •  5
  • l0st3d  · 技术社区  · 15 年前

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

    我找到了一个图书馆 here 这是我所需要的,我在itplaylist.java中添加了一些代码来调用“addtrack”方法(上面提到 in the docs )在iTunes对象itPlaylist上:

     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
    

    我做错什么了?

    2 回复  |  直到 13 年前
        1
  •  1
  •   Faxwell Mingleton    15 年前

    我在Java中暂时没有做过任何iTunes的东西,但从我的经验来看,我记得界面是相当多变的。

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

    从您提供的转储文件来看,Jacob中的底层C似乎正试图通过iTunes COM接口修改等效的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);
    }
    

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

    如果这能给你带来成功,请告诉我!

    编辑 在重新阅读了我的帖子之后,我意识到我忘记了这种方法,因为它可以让雅各布COM桥远离更高层次的东西,这可以说是更好的方法:

    ((ITUserPlaylist)this).addTrack(track);
    
        2
  •  1
  •   l0st3d    15 年前

    我的答案是联系我正在使用的库的开发人员,让他发布一个新版本的库。如果您想这样做,请至少使用0.2版,它将正确区分itplaylist对象和ituserplaylist对象,而ituserplaylist对象(如lurkingfridge79所述)是唯一可以通过COM API添加曲目的播放列表类型。