如何通过 ScriptingBridge 检索 iTunes 曲目?
我有两种情况。给定歌曲的曲目 ID,将评级设置为某个整数。第二个是相同的,除了给我一个轨道 ID 数组。我知道我可以使用 ScriptingBridge 根据歌曲名称搜索 iTunesTrack 对象,但是有什么方法可以根据曲目 ID 获取它吗?大致如下:
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
NSInteger *rating;
NSInteger *id;
if ( [iTunes isRunning] ) {
iTunesTrack *track = [ iTunes trackForDatabaseID:id ];
[ track setValue:rating forkey:@"rating" ];
}
对于第二种情况,有没有办法在给定曲目 id 数组的情况下检索 iTunesTrack 的 SBElementArray 对象?比如:
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
NSArray *ids; //array of NSIntegers
if ( [iTunes isRunning] ) {
SBElementArray *tracks = [ iTunes tracksForDatabaseIDs:ids ];
[ tracks setValue:rating forkey:@"rating" ];
}
我相信这比根据歌曲名称迭代搜索库更有效。
I have two situations. Given a track id of a song, set the rating to some integer. The second is the same except I am given an array of track ids. I know I can use the ScriptingBridge to search for the iTunesTrack object based on a song's name, but is there some way to get it based off the track id? Something along the lines of:
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
NSInteger *rating;
NSInteger *id;
if ( [iTunes isRunning] ) {
iTunesTrack *track = [ iTunes trackForDatabaseID:id ];
[ track setValue:rating forkey:@"rating" ];
}
For the second situation, is there a way to retrieve a SBElementArray object of iTunesTrack given an array of track ids? Something like:
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
NSArray *ids; //array of NSIntegers
if ( [iTunes isRunning] ) {
SBElementArray *tracks = [ iTunes tracksForDatabaseIDs:ids ];
[ tracks setValue:rating forkey:@"rating" ];
}
I believe this would be more efficient than iteratively searching the library based on a song's name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近刚做了这个。像这样的东西应该对你有用。您需要询问库播放列表(在此示例中名为
libraryPlaylist
)而不是应用程序。如果
trackIDs
数组仅包含单个项目,则效果很好,因此无需为这种情况编写特殊代码。I just did this recently. Something like this should work for you. You need to ask the library playlist (named
libraryPlaylist
in this example) and not the application.And that works just fine if the
trackIDs
array only contains a single item, so there's no need to write special code for that case.