Class: ITunesObserver
- Inherits:
-
Object
show all
- Defined in:
- lib/itunes_observer.rb
Defined Under Namespace
Classes: Observer, Result
Constant Summary
collapse
- VERSION =
'0.1.1'
- STATES =
{
:playing => 'Playing',
:paused => 'Paused',
:stopped => 'Stopped'
}
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ITunesObserver.
12
13
14
15
16
|
# File 'lib/itunes_observer.rb', line 12
def initialize(&callback)
@observer = Observer.alloc.init
add_callback(STATES[:playing], &callback)
end
|
Instance Method Details
#finish ⇒ Object
38
39
40
|
# File 'lib/itunes_observer.rb', line 38
def finish
@observer.finish
end
|
#on_pause(&callback) ⇒ Object
22
23
24
|
# File 'lib/itunes_observer.rb', line 22
def on_pause(&callback)
add_callback(STATES[:paused], &callback)
end
|
#on_play(&callback) ⇒ Object
18
19
20
|
# File 'lib/itunes_observer.rb', line 18
def on_play(&callback)
add_callback(STATES[:playing], &callback)
end
|
#on_stop(&callback) ⇒ Object
26
27
28
|
# File 'lib/itunes_observer.rb', line 26
def on_stop(&callback)
add_callback(STATES[:stopped], &callback)
end
|
#run(stop_after = nil) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/itunes_observer.rb', line 30
def run(stop_after = nil)
if stop_after
OSX::NSRunLoop.currentRunLoop.runUntilDate(Time.now + stop_after)
else
OSX::NSRunLoop.currentRunLoop.run
end
end
|