Ruby on Rails: Get mediaplayer information (iTunes, TRAKTOR, Cog; current song + playlist)

纵饮孤独 提交于 2019-12-08 08:16:25

问题


I want to write a small web app which does this things:

  • deliver a web page to display the current song and some meta data
  • provide a web api which can be queried for the next song to allow the page to update without page load

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.


回答1:


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'

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>



回答2:


I've never even heard of the other two players you are mentioning, but with iTunes this is definitely possible. Look at this project for example: http://code.google.com/p/itunes-rails/

There should be a scripting bridge that can communicate with iTunes. Not sure about the other players, though.



来源:https://stackoverflow.com/questions/5617609/ruby-on-rails-get-mediaplayer-information-itunes-traktor-cog-current-song

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