Class: Muzak::Player::MultiPlayer
- Inherits:
-
StubPlayer
- Object
- StubPlayer
- Muzak::Player::MultiPlayer
- Defined in:
- lib/muzak/player/multiplayer.rb
Overview
Instance Attribute Summary collapse
-
#players ⇒ Array<StubPlayer>
readonly
The players associated with this multiplayer.
Attributes inherited from StubPlayer
Class Method Summary collapse
-
.available? ⇒ Boolean
Whether or not all of the players are available.
Instance Method Summary collapse
-
#activate! ⇒ void
Activates each player under the multiplayer.
-
#clear_queue ⇒ void
Clears the internal queue.
-
#deactivate! ⇒ void
Deactivates each player under the multiplayer.
-
#enqueue_album(album) ⇒ void
Tell all players to add the given album to its queue.
-
#enqueue_playlist(playlist) ⇒ void
Tell all players to add the given playlist to its queue.
-
#enqueue_song(song) ⇒ void
Tell all players to add the given song to its queue.
-
#initialize(instance) ⇒ MultiPlayer
constructor
A new instance of MultiPlayer.
-
#list_queue ⇒ Array<Song>
Get the internal queue of the first player.
-
#next_song ⇒ void
Tell all players to play the next song in its queue.
-
#now_playing ⇒ Song?
Get the currently loaded song.
-
#pause ⇒ void
Tell all players to pause playback.
-
#play ⇒ void
Tell all players to begin playback.
-
#playing? ⇒ Boolean
Whether or not any of the players are currently playing.
-
#previous_song ⇒ void
Tell all players to play the previous song in its queue.
-
#running? ⇒ Boolean
Whether or not any of the players are currently running.
-
#shuffle_queue ⇒ void
Shuffle the internal queue.
Methods inherited from StubPlayer
Methods included from Utils
album_art?, #build_response, #danger, #debug, #debug?, #error, #error!, music?, #output, #pretty, #verbose, #verbose?, which?
Constructor Details
#initialize(instance) ⇒ MultiPlayer
Returns a new instance of MultiPlayer.
17 18 19 20 21 22 |
# File 'lib/muzak/player/multiplayer.rb', line 17 def initialize(instance) super(instance) klasses = Config.multiplayer_players.map { |p| Player::PLAYER_MAP[p] } @players = klasses.map { |pk| pk.new(instance) } end |
Instance Attribute Details
#players ⇒ Array<StubPlayer> (readonly)
Returns the players associated with this multiplayer.
8 9 10 |
# File 'lib/muzak/player/multiplayer.rb', line 8 def players @players end |
Class Method Details
.available? ⇒ Boolean
Returns whether or not all of the players are available.
11 12 13 14 |
# File 'lib/muzak/player/multiplayer.rb', line 11 def self.available? klasses = Config.multiplayer_players.map { |p| Player::PLAYER_MAP[p] } klasses.all?(&:available?) end |
Instance Method Details
#activate! ⇒ void
This method returns an undefined value.
Activates each player under the multiplayer.
31 32 33 34 |
# File 'lib/muzak/player/multiplayer.rb', line 31 def activate! debug "activating #{self.class}" @players.each(&:activate!) end |
#clear_queue ⇒ void
This method returns an undefined value.
Clears the internal queue.
128 129 130 131 |
# File 'lib/muzak/player/multiplayer.rb', line 128 def clear_queue return unless running? @players.each(&:clear_queue) end |
#deactivate! ⇒ void
This method returns an undefined value.
Deactivates each player under the multiplayer.
38 39 40 41 |
# File 'lib/muzak/player/multiplayer.rb', line 38 def deactivate! debug "deactivating #{self.class}" @players.each(&:deactivate!) end |
#enqueue_album(album) ⇒ void
Activates all players if not already activated.
This method returns an undefined value.
Tell all players to add the given album to its queue.
92 93 94 95 |
# File 'lib/muzak/player/multiplayer.rb', line 92 def enqueue_album(album) activate! unless running? @players.each { |p| p.enqueue_album(album) } end |
#enqueue_playlist(playlist) ⇒ void
Activates all players if not already activated.
This method returns an undefined value.
Tell all players to add the given playlist to its queue.
101 102 103 104 |
# File 'lib/muzak/player/multiplayer.rb', line 101 def enqueue_playlist(playlist) activate! unless running? @players.each { |p| p.enqueue_playlist(playlist) } end |
#enqueue_song(song) ⇒ void
Activates all players if not already activated.
This method returns an undefined value.
Tell all players to add the given song to its queue.
83 84 85 86 |
# File 'lib/muzak/player/multiplayer.rb', line 83 def enqueue_song(song) activate! unless running? @players.each { |p| p.enqueue_song(song) } end |
#list_queue ⇒ Array<Song>
This includes songs already played.
Get the internal queue of the first player.
109 110 111 |
# File 'lib/muzak/player/multiplayer.rb', line 109 def list_queue @players.first.list_queue end |
#next_song ⇒ void
Does nothing if the current song is the last.
This method returns an undefined value.
Tell all players to play the next song in its queue.
68 69 70 |
# File 'lib/muzak/player/multiplayer.rb', line 68 def next_song @players.each(&:next_song) end |
#now_playing ⇒ Song?
Get the currently loaded song.
135 136 137 138 |
# File 'lib/muzak/player/multiplayer.rb', line 135 def @players[1]. @players.first. end |
#pause ⇒ void
Does nothing is playback is already paused.
This method returns an undefined value.
Tell all players to pause playback.
54 55 56 57 |
# File 'lib/muzak/player/multiplayer.rb', line 54 def pause return unless running? @players.each(&:pause) end |
#play ⇒ void
Does nothing is playback is already in progress.
This method returns an undefined value.
Tell all players to begin playback.
46 47 48 49 |
# File 'lib/muzak/player/multiplayer.rb', line 46 def play return unless running? @players.each(&:play) end |
#playing? ⇒ Boolean
Returns Whether or not any of the players are currently playing.
60 61 62 63 |
# File 'lib/muzak/player/multiplayer.rb', line 60 def return false unless running? @players.any?(&:playing?) end |
#previous_song ⇒ void
Does nothing if the current song is the first.
This method returns an undefined value.
Tell all players to play the previous song in its queue.
75 76 77 |
# File 'lib/muzak/player/multiplayer.rb', line 75 def previous_song @players.each(&:previous_song) end |
#running? ⇒ Boolean
Returns whether or not any of the players are currently running.
25 26 27 |
# File 'lib/muzak/player/multiplayer.rb', line 25 def running? @players.any?(&:running?) end |
#shuffle_queue ⇒ void
This method returns an undefined value.
Shuffle the internal queue.
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/muzak/player/multiplayer.rb', line 115 def shuffle_queue return unless running? # XXX: shuffling is currently done internally within each player, # meaning that shuffling within multiplayer would leave each # player in an inconsistent queue state. # the solution to this is probably to list the queue, shuffle that # list, clear the player's queue, and then load the single shuffled # list back into each player. danger "shuffling doesn't currently make any sense in multiplayer!" end |