How to get currently playing track in Spotify Mac from Cocoa [closed]

ぃ、小莉子 提交于 2019-12-08 03:55:05

问题


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.

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


回答1:


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.)

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

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



来源:https://stackoverflow.com/questions/11236413/how-to-get-currently-playing-track-in-spotify-mac-from-cocoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!