我正在尝试使用AutoHotkey(v1.1)和iTunes Windows 11从其持久ID中检索跟踪对象。该脚本运行良好,直到我尝试使用ItemByPersistentID
方法。
objITunesunesApp := ComObjCreate("iTunes.Application")
objITunesLibrary := objITunesunesApp.Sources.Item(1)
objITunesPlaylist := objITunesLibrary.Playlists.Item(1)
objITunesTrack := objITunesPlaylist.Tracks.Item(1)
; Test if objects are OK
MsgBox, % objITunesTrack.Name ; Display the song name - OK
; Get high and low IDs
intIDHigh := objITunesunesApp.ITObjectPersistentIDHigh(objITunesTrack)
intIDLow := objITunesunesApp.ITObjectPersistentIDLow(objITunesTrack)
MsgBox, %intIDHigh% %intIDLow% ; Display: "-1071797520 -947434212" OK
; Try to get the track again using the persistent IDs
objTrackByID := objITunesLibrary.ItemByPersistentID(intIDHigh, intIDLow)
; Error: 0x80020006 - Name unknown
; Specifically: ItemByPersistentID
MsgBox, % "objTrackByID.Name: " . objTrackByID.Name ; name empty
我是否以正确的方式致电ItemByPersistentID
?感谢。
答案 0 :(得分:0)
除非其他人提供有关ItemByPersistentID
功能的答案,否则我发现了另一种方法。更麻烦,因为您必须保存关于轨道的4个ID才能通过ID检索它,但它确实有效。
objITunesunesApp := ComObjCreate("iTunes.Application") ; will launch iTunes if not running
objITunesLibrary := objITunesunesApp.Sources.Item(1) ; main library
objITunesPlaylist := objITunesLibrary.Playlists.Item(1) ; main playlist
objITunesTrack := objITunesPlaylist.Tracks.Item(1) ; first track
; get IDs for this track
sourceID := objITunesTrack.sourceID
playlistID := objITunesTrack.playlistID
databaseID := objITunesTrack.trackDatabaseID
trackID := objITunesTrack.trackID
; check track name to see if we can retrieve the same track by IDs
name := objITunesTrack.name
MsgBox, % ""
. "sourceID: " . sourceID . "`n"
. "playlistID: " . playlistID . "`n"
. "databaseID: " . databaseID . "`n"
. "trackID: " . trackID . "`n"
. "name: " . name . "`n"
; retrieve the same track using IDs
objTrackByID := objITunesunesApp.GetITObjectByID(sourceID, playlistID, trackID, databaseID)
MsgBox, % "objTrackByID.name: " . objTrackByID.name ; same name as previously -> WORKS!
对于同一播放列表中的所有曲目, sourceID
和playlist
都不会更改。因此,我们只需要为每首曲目保存2个ID,以便能够检索曲目。最后,如果可行,只要ItemByPersistentID
检索就不会复杂得多。
答案 1 :(得分:0)
刚刚在原始脚本中找到错误:
objTrackByID := objITunesPlaylist.Tracks.ItemByPersistentID(intIDHigh, intIDLow)
ItemByPersistentID
是跟踪收藏的方法。