iTunes Scripting Bridge - 如何播放特定曲目

发布于 2024-09-16 11:14:14 字数 325 浏览 2 评论 0原文

我正在编写一个使用脚本桥来控制 iTunes 的 Mac 应用程序。我已经生成了头文件 iTunes.h,SBApplication 对象可以告诉我各种奇妙的事情。

然而,命令似乎非常有限。有一个“playpause”功能,但我看不出有什么办法可以做到这一点

// iTunes 是我的 SBApplication 对象 [iTunes播放:@《水上烟雾》];

执行此操作的 Applescript 相当简单,

告诉 iTunes 播放歌曲名称

,而这个脚本桥应该是我在 Objective C 中控制可脚本化对象的超酷且强大的方式,所以我在这里缺少什么?

I am writing a mac application that uses the scripting bridge to control iTunes. I have generated the header file iTunes.h, and the SBApplication object can tell me all kinds of wonderful things.

However, the commands seem very limited. There is a 'playpause' function, but I see no way to do this

// iTunes is my SBApplication Object
[iTunes play:@"Smoke On The Water"];

The Applescript to do this is the fairly simple

tell iTunes play songName

and this Scripting bridge is supposed to be the super cool and powerful way for me to control scriptable objects in Objective C, so what am I missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゃ懵逼小萝莉 2024-09-23 11:14:14

您应该只在 iTunesTrack 对象上发送消息“playOnce:(BOOL)”。下面是一个示例:

iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
iTunesPlaylist *playlist = [iTunes currentPlaylist];
SBElementArray *tracks = [playlist tracks];
[[tracks objectAtIndex:0] playOnce:YES];

这将播放当前播放列表中的第一首曲目。适应你的情况。

You should just send the message "playOnce:(BOOL)" on your iTunesTrack object. Here's an example:

iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
iTunesPlaylist *playlist = [iTunes currentPlaylist];
SBElementArray *tracks = [playlist tracks];
[[tracks objectAtIndex:0] playOnce:YES];

This will play the first track on the current playlist. Adapt to your situation.

迷迭香的记忆 2024-09-23 11:14:14

在网络上搜索等效的 AppleScript 片段或在 AppleScript 编辑器应用程序中查看 iTune 的脚本字典。然后将生成的脚本转换为脚本桥命令。可能的 AppleScript 等效项是:

tell application "iTunes"
    play first item of (search first library playlist for "Smoke On The Water")
end tell

PS 您可能会发现 objc-appscript 更容易工作with 为此(或者,如果 Objective C 不是必需的,则使用其近亲 py-appscript 或 rb-appscript)。

Search the web for equivalent AppleScript snippets or view iTune's scripting dictionary in the AppleScript Editor app. Then translate the resulting script into scripting bridge commands. A possible AppleScript equivalent is:

tell application "iTunes"
    play first item of (search first library playlist for "Smoke On The Water")
end tell

P.S. You might find objc-appscript easier to work with for this (or, if Objective C is not a requirement, its cousins, py-appscript or rb-appscript).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文