问题描述
我想编写一个小型的Web应用程序来完成以下任务:
I want to write a small web app which does this things:
- 提供一个网页以显示当前歌曲和一些元数据
- 提供一个网络api,可以查询下首歌曲以允许页面更新而无需页面加载
没什么大不了的,我唯一无法估计的部分是是否可以访问 iTunes , TRAKTOR ,并在可能的情况下使用 Cog 从ruby on rails应用程序中获得.
No big deal, the only part I can't estimate is if it's possible to access the current song of iTunes, TRAKTOR and if possible Cog from a ruby on rails application.
如果我也可以访问播放列表以显示下一首歌曲,那将特别好.
It would be especially nice if I can access the playlist, too to display the following song, too.
推荐答案
我将通过命令行使用applescript.我没有Traktor Pro或Coq,但是您可以通过OS X的脚本编辑器中的AppleScript词典查看器查看哪些对象可用.对于iTunes,命令为:
I would use applescript via the command-line. I don't have Traktor Pro or Coq, but you can look at what objects are available via the AppleScript Dictionary viewer in OS X's Script Editor. For iTunes, the command would be:
osascript -e 'tell application "iTunes" to get name of current track'
osascript -e 'tell application "iTunes" to get name of every track of current playlist'
您可以从Rails应用程序(需要以您的用户帐户运行)执行命令,如下所示:
You would execute the command from your rails app (which would need to be running as your user account) like this:
def show
@current_track = `osascript -e 'tell application "iTunes" to get name of current track'`
end
...
<h1>The current track is: <%= @current_track -%></h1>
这篇关于Ruby on Rails:获取媒体播放器信息(iTunes,TRAKTOR,Cog;当前歌曲和播放列表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!