如何从 iTunes 获取歌曲信息?
我正在为 Mac OS X 开发一个应用程序来显示 iTunes 正在播放的歌曲的歌词。我做了一些搜索,只找到了使用AppleScript来实现它的方法。是否有 Objective-C 的 API 可用于从 iTunes 获取有关歌曲的信息?我想知道 Bowtie、CoverSutra 和 Last.fm 是如何做到的。
I'm developing an app for Mac OS X to display lyric of the song iTunes is playing. I've done some searches and found only the way using AppleScript to realize it. Is there an API for Objective-C that I can use to fetch information about the song from iTunes? I want to know how Bowtie, CoverSutra and Last.fm did it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 10.9 中,您可以使用 iTunes Library 框架 (/Library/ Frameworks/iTunesLibrary.framework) 适用于 iTunes 11。
In 10.9 you can use iTunes Library Framework (/Library/Frameworks/iTunesLibrary.framework) for iTunes 11.
请参阅我的问题的答案:
一开始可能会有点棘手,但与 Cocoa 一样:做过一次后就很容易了。
See the answer to my question:
It can be a bit tricky in the beginning, but as always with Cocoa: it's easy after you've done it once.
据我所知,除了 AppleScript 接口之外,没有 Apple 提供的 API。
但碰巧的是,只要曲目发生变化,iTunes 就会发布分布式通知,这样您就可以收听这些通知并以这种方式获取当前播放的歌曲信息。
请参阅 Objective-C Mac OS X 分布式通知 iTunes
I'我从未见过这些通知的任何官方文档,所以我不知道您是否可以指望它们在未来发挥作用,但它们在过去十年中一直有效。
There's no Apple-supplied API that I know of, other than the AppleScript interface.
But it just so happens that iTunes posts distributed notifications whenever the track changes, so you can listen for those and get the currently playing song info that way.
See Objective-C Mac OS X Distributed notifications iTunes
I've never seen any official documentation of these notifications so I don't know if you can count on them working in the future, but they've worked for like the past decade.