通过 ScriptingBridge 在 iTunes 中播放特定标题
我正在尝试编写一个通过 ScriptingBridge 与 iTunes 交互的应用程序。到目前为止我工作得很好,但这种方法的选择似乎非常有限。
我想播放给定名称的歌曲,但似乎没有办法做到这一点。我在 iTunes.h 中没有找到任何类似的东西...
在 AppleScript 中,它只有三行代码:
tell application "iTunes"
play (some file track whose name is "Yesterday")
end tell
然后 iTunes 开始播放经典的披头士乐队歌曲。 我可以使用 ScriptingBridge 执行此操作,还是必须从我的应用程序运行此 AppleScript?
I'm trying to write an application that interacts with iTunes via ScriptingBridge. I works well so far, but the options of this method seem to be very limited.
I want to play song with a given name, but it looks like there's no way to do this. I haven't found anything similar in iTunes.h…
In AppleScript it's just three lines of code:
tell application "iTunes"
play (some file track whose name is "Yesterday")
end tell
And then iTunes starts to play a classic Beatles song.
Is there any was I can do this with ScriptingBridge or do I have to run this AppleScript from my app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不像 AppleScript 版本那么简单,但肯定是可能的。
方法一
获取指向 iTunes 库的指针:
获取包含库中所有音频文件曲目的数组:
然后过滤该数组以查找具有您要查找的标题的曲目。
方法二
获取指向 iTunes 库的指针,如上所示。然后使用 Scripting Bridge
searchFor: only:
方法:对方法二的警告:iTunes.h 文件错误地声明
searchFor: only:
方法返回 iTunesTrack*,当事实上(出于明显的原因)它返回一个 SBElementArray*。您可以编辑头文件以消除生成的编译器警告。It's not as simple as the AppleScript version, but it's certainly possible.
Method one
Get a pointer to the iTunes library:
Get an array containing all the audio file tracks in the library:
Then filter the array to find tracks with the title you're looking for.
Method two
Get a pointer to the iTunes library as above. Then use the Scripting Bridge
searchFor: only:
method:Caveat to method two: The iTunes.h file incorrectly claims that the
searchFor: only:
method returns an iTunesTrack*, when in fact (for obvious reasons) it returns an SBElementArray*. You can edit the header file to get rid of the resulting compiler warning.