get a specific track in itunes via ScriptingBridge [closed]

空扰寡人 提交于 2019-12-11 02:46:52

问题


I'm updating my OS X program to accept iTunes drops, modify the metadata in the file, then refresh (Get Info) the dropped file(s) so iTunes can update its' metadata library.

I've got the drops working, which provide a dictionary of some misc info about the file including track ID, persistent ID, and Location. I'm at the point now where I need to get a specific track, either by file location or the persistant ID provided by the drop info, so I can call the refresh method on it to force iTunes to reexamine the file and update the changes to the metadata.

I've got the iTunes header file imported and the SBApplication object created, I'm pretty stuck at this point on an efficient way to get the proper track.


回答1:


As stated, I already had access to some info about a file provided by an iTunes drop. I needed to match up info about that file based on either the file name or persistentID provided by the drop to the file in the iTunes library my solution was to use a predicate filter on the iTunes library against the library collection returned by the iTunes scripting bridge.

    iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];

    SBElementArray *sources = [iTunes sources];

    SBElementArray *entireLibrary = [[[[sources objectAtIndex:0] libraryPlaylists] objectAtIndex:0] fileTracks];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"persistentID == %@", persistentID];

    [entireLibrary filterUsingPredicate:predicate];



回答2:


This is how I get the current track info from iTunes usingScriptingBridge:

iTunesApplication * iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
NSString * artist    = [[iTunes currentTrack] artist];
NSString * trackname = [[iTunes currentTrack] name];
/* etc. */


来源:https://stackoverflow.com/questions/5766615/get-a-specific-track-in-itunes-via-scriptingbridge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!