Class: Walkman::Player
- Inherits:
-
Object
- Object
- Walkman::Player
- Defined in:
- lib/walkman/player.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#current_song ⇒ Object
Returns the value of attribute current_song.
-
#playing ⇒ Object
Returns the value of attribute playing.
- #playlist ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Player
constructor
A new instance of Player.
- #next(count = 1) ⇒ Object
- #play ⇒ Object
- #services ⇒ Object
- #shutdown ⇒ Object
- #startup ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Player
Returns a new instance of Player.
12 13 14 15 16 |
# File 'lib/walkman/player.rb', line 12 def initialize @current_song = nil @playing = false @running = false end |
Instance Attribute Details
#current_song ⇒ Object
Returns the value of attribute current_song.
7 8 9 |
# File 'lib/walkman/player.rb', line 7 def current_song @current_song end |
#playing ⇒ Object
Returns the value of attribute playing.
7 8 9 |
# File 'lib/walkman/player.rb', line 7 def @playing end |
Instance Method Details
#next(count = 1) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/walkman/player.rb', line 84 def next(count = 1) if @current_song = playlist.next(count) @playing = true else stop end end |
#play ⇒ Object
68 69 70 71 72 |
# File 'lib/walkman/player.rb', line 68 def play Walkman.logger.debug("player play") @playing = true end |
#services ⇒ Object
18 19 20 21 22 |
# File 'lib/walkman/player.rb', line 18 def services @services ||= begin Hash[SERVICES.map { |service| [service.name, service.new] }] end end |
#shutdown ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/walkman/player.rb', line 59 def shutdown @running = false @play_loop.join if @play_loop services.each do |key, service| service.shutdown end end |
#startup ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/walkman/player.rb', line 24 def startup services.each do |key, service| service.startup end @running = true @play_loop = Thread.new do current_loop_song = nil last_loop_song = nil while @running if @playing current_loop_song = @current_song if current_loop_song.nil? self.next elsif !last_loop_song.nil? && current_loop_song != last_loop_song stop current_loop_song = nil @playing = true # have to reset this due to calling stop elsif last_loop_song.nil? play_song(current_loop_song) end last_loop_song = current_loop_song else last_loop_song = nil end sleep 0.1 end end end |