Class: Radiodan::Player
- Inherits:
-
Object
- Object
- Radiodan::Player
- Extended by:
- Forwardable
- Includes:
- EventBinding, Logging
- Defined in:
- lib/radiodan/player.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#playlist ⇒ Object
Returns the value of attribute playlist.
Instance Method Summary collapse
- #adapter? ⇒ Boolean
- #respond_to?(method) ⇒ Boolean
- #state ⇒ Object
-
#sync ⇒ Object
Sync checks the current status of the player.
Methods included from EventBinding
#events, #register_event, #trigger_event
Methods included from Logging
included, level, level=, #logger, output, output=
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
89 90 91 92 93 94 95 |
# File 'lib/radiodan/player.rb', line 89 def method_missing(method, *args, &block) if adapter.respond_to? method adapter.send method, *args, &block else super end end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
12 13 14 |
# File 'lib/radiodan/player.rb', line 12 def adapter @adapter end |
#playlist ⇒ Object
Returns the value of attribute playlist.
12 13 14 |
# File 'lib/radiodan/player.rb', line 12 def playlist @playlist end |
Instance Method Details
#adapter? ⇒ Boolean
19 20 21 |
# File 'lib/radiodan/player.rb', line 19 def adapter? !adapter.nil? end |
#respond_to?(method) ⇒ Boolean
79 80 81 82 83 84 85 |
# File 'lib/radiodan/player.rb', line 79 def respond_to?(method) if adapter.respond_to? method true else super end end |
#state ⇒ Object
32 33 34 |
# File 'lib/radiodan/player.rb', line 32 def state adapter.playlist end |
#sync ⇒ Object
Sync checks the current status of the player.
Is it paused? Playing? What is it playing?
It compares the expected to actual statuses and
triggers events if there is a difference.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/radiodan/player.rb', line 42 def sync return false unless adapter? current = adapter.playlist expected = playlist sync = Radiodan::PlaylistSync.new expected, current synced = sync.sync? unless synced # playback state sync.errors.each do |e| case e when :state logger.debug "Expected State: #{expected.state} Got: #{current.state}" trigger_event :play_state, current.state when :mode logger.debug "Expected Mode: #{expected.mode} Got: #{current.mode}" trigger_event :play_mode, current.mode when :new_tracks logger.debug "Expected: #{expected.current.inspect} Got: #{current.current.inspect}" trigger_event :playlist, expected when :add_tracks logger.debug "Found additional tracks to enqueue" trigger_event :enqueue, expected.tracks[current.tracks.size..-1] trigger_event :play_pending if sync.errors.include?(:state) && current.state == :stop when :volume logger.debug "Expected Volume: #{expected.volume} Got: #{current.volume}" trigger_event :volume, expected.volume end end end trigger_event :sync, current synced end |