如何获得当前播放曲目在Spotify Mac从可可 [英] How to get currently playing track in Spotify Mac from Cocoa

查看:240
本文介绍了如何获得当前播放曲目在Spotify Mac从可可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个适用于Mac的lyric应用程序,我想在我的应用程序中添加Spotify支持。我只需要检索当前播放曲目的spotify客户端为Mac,并获得通知如果播放状态已更改。

I'm developing a lyric application for Mac and I want to add Spotify support to my app. I just need to retrieve currently playing track on spotify client for Mac and get notified if playing state has changed.

有没有任何API在我的应用程序中使用这样做?

is there any API to use in my app for doing this?

推荐答案

为了在播放状态改变时通知您com.spotify.client.PlaybackStateChanged。在这里至少还有两个问题要求如何做,其中一个有示例代码,所以尝试搜索。 (或者只是启动通知监视器,你可以看到他们自己,并应该很容易找出如何编写代码来处理它们。)

To get notified when playing state has changed (which tells you the new track), you watch for a distributed notification called "com.spotify.client.PlaybackStateChanged". There are at least two other questions here asking how to do that, one of which has sample code, so try searching for that. (Or just fire up Notification Watcher and you can see them for yourself, and it should be easy to figure out how to write the code to handle them.)

如果你想要手动检查当前轨迹(例如,在启动时),您可以使用Spotify AppleScript界面​​(当然您也可以通过ScriptingBridge,appscript等访问),如下所示:

If you want to check the current track manually (e.g., at startup), you can use the Spotify AppleScript interface (which of course you can also access via ScriptingBridge, appscript, etc.), like this:

tell application "Spotify"
  name of current track
end tell

艺术家有类似的属性等。启动AppleScript编辑器,并打开Spotify字典获取完整的详细信息。

There are similar properties for the artist, etc. Fire up AppleScript Editor and open the Spotify Dictionary for full details.

这篇关于如何获得当前播放曲目在Spotify Mac从可可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆