Java iTunes COM-интерфейс Jacob - получение PersistentID (PersistentIDLow и PersistentIDHigh) - PullRequest
1 голос
/ 08 мая 2020

У меня есть некоторые проблемы с пониманием интерфейса iTunes COM с Джейкобом в отношении PersistentID ( PersistentIDLow и PersistentIDHigh ) для идентификации списков воспроизведения и треков по уникальным в iTunes.

Надеюсь, кто-нибудь скажет мне, что я делаю неправильно.

Вот мой пример кода для чтения одного списка воспроизведения List 1 iTunes. Пример показывает в комментариях пробную версию для чтения PersistentID для списка воспроизведения Список 1 и для каждой дорожки списка воспроизведения.

Но Dispatch не работает, см. Строки кода с комментарием " не работает ».

Исключение в потоке« main »com.jacob.com.ComFailException: не удается сопоставить имя с dispid: GetObjectPersistentIDLow

Исключение в потоке« main » com.jacob.com.ComFailException: не удается сопоставить имя с диспидом: GetObjectPersistentIDHigh

public static void main(String args[]){
    System.setProperty("jacob.dll.path", "C:\\Dev\\iTunesTest\\dll\\jacob-1.18-M2-x86.dll");
    
    // build iTunes activeX component
    ActiveXComponent g_iTunes = new ActiveXComponent("iTunes.Application");
    // get iTunes Sources
    Dispatch g_sources = Dispatch.call(g_iTunes, "Sources").toDispatch(); 
    // determine iTunes Library Source ID
    int sourceID = 0;
    for (int i=1;i<=Dispatch.get(g_sources, "Count").getInt();i++){  
        Dispatch itemSearch = Dispatch.call(g_sources, "Item", i).toDispatch();
        if (ITunesSourceKind.values()[Dispatch.get(itemSearch, "Kind").getInt()].toString().equals("ITSourceKindLibrary")){
            sourceID = Dispatch.get(itemSearch, "Index").getInt();
        }
        itemSearch.safeRelease();
    }
    // get iTunes Library Source
    Dispatch g_source = Dispatch.call(g_sources, "Item", sourceID).toDispatch();
    // get iTunes Playlists
    Dispatch g_playlists = Dispatch.get(g_source, "Playlists").toDispatch();    
    // get iTunes Playlist byName
    Dispatch g_playlistItem = Dispatch.call(g_playlists, "ItemByName", "List 1").toDispatch();
    // get iTunes Tracks for Playlist
    Dispatch g_tracks = Dispatch.get(g_playlistItem, "Tracks").toDispatch();   
                
    String name = Dispatch.get(g_playlistItem, "Name").getString();
    System.out.println("Playlist: " + name);
    // doesn't work
    System.out.println("ID Low  : " + Dispatch.call(g_playlistItem, "GetObjectPersistentIDLow").getLong());
    System.out.println("ID High : " + Dispatch.call(g_playlistItem, "GetObjectPersistentIDHigh").getLong());
        
    // get every iTunes playlist track
    int playlistSongCount = Dispatch.get(g_tracks, "Count").getInt();
    for (int i=1; i<=playlistSongCount; i++){
        // get single iTunes playlist track
        Dispatch track = Dispatch.call(g_tracks, "Item", i).toDispatch();
        System.out.println(" Song Name: " + Dispatch.get(track, "Name").getString());
        // doesn't work
        System.out.println(" ID Low   : " + Dispatch.call(track, "GetObjectPersistentIDLow").getLong());
        System.out.println(" ID High  : " + Dispatch.call(track, "GetObjectPersistentIDHigh").getLong());
        if(track != null){
            track.safeRelease();
        }
    }
    
    // release objects
    if(g_tracks != null){
        g_tracks.safeRelease();
    }
    if(g_playlistItem != null){
        g_playlistItem.safeRelease();
    }
    if(g_playlists != null){
        g_playlists.safeRelease();
    }
    if(g_source != null){
        g_source.safeRelease();
    }
    if(g_sources != null){
        g_sources.safeRelease();
    }
    if(g_iTunes != null){
        // close iTunes
        //g_iTunes.invoke("Quit");          
        g_iTunes.safeRelease();
    }
}

Я думал, что это должно сработать, см. справочный URL Java -iTunes-API

Итоги:

    /**
 * Returns the high 32 bits of the persistent ID of the specified IITObject.
 * See the documentation on IITObject for more information on persistent
 * IDs.
 * 
 * The object may be a source, playlist, or track.
 * 
 * @param iObject
 *            The object to fetch the High Persistent ID.
 * @return The high 32 bits of the 64-bit persistent ID.
 */
public long getITObjectPersistentIDHigh(ITObject iObject) {
    Dispatch object = iObject.fetchDispatch();
    return Dispatch.call(object, "GetObjectPersistentIDHigh", object)
            .getLong();
}

/**
 * Returns the low 32 bits of the persistent ID of the specified IITObject.
 * See the documentation on IITObject for more information on persistent
 * IDs.
 * 
 * The object may be a source, playlist, or track.
 * 
 * @param iObject
 *            The object to fetch the Low Persistent ID.
 * @return The low 32 bits of the 64-bit persistent ID.
 */
public long getITObjectPersistentIDLow(ITObject iObject) {
    Dispatch object = iObject.fetchDispatch();
    return Dispatch.call(object, "GetObjectPersistentIDLow", object)
            .getLong();
}

Есть идеи, что я делаю не так?

Большое вам спасибо.

Майкл

...