Created
March 21, 2012 02:18
-
-
Save youpy/2143777 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ubygems' | |
require 'itunes_observer' | |
require 'eventmachine' | |
class EventMachine::ITunesWatch | |
def initialize | |
@observer= ITunesObserver.new | |
@observer.on_pause do |result| | |
paused(result) | |
end | |
@observer.on_play do |result| | |
played(result) | |
end | |
@observer.on_stop do |result| | |
stopped(result) | |
end | |
end | |
def paused(result) | |
end | |
def played(result) | |
end | |
def stopped(result) | |
end | |
def start | |
@timer = EventMachine::add_periodic_timer(1) do | |
@observer.run(0) | |
end | |
end | |
def stop | |
@timer.cancel if @timer | |
end | |
end | |
module Watcher | |
def played(result) | |
puts 'played' | |
end | |
def paused(result) | |
puts 'paused' | |
end | |
def stopped(result) | |
puts 'stopped' | |
end | |
end | |
module EventMachine | |
def self.watch_itunes(handler = nil, *args, &block) | |
klass = klass_from_handler(EventMachine::ITunesWatch, handler, *args); | |
c = klass.new(*args, &block) | |
c.start | |
c | |
end | |
end | |
EM.run { | |
EM.watch_itunes(Watcher) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment