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.
19 20 21 22 23 24 |
# File 'lib/muzak/player/multiplayer.rb', line 19 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.
10 11 12 |
# File 'lib/muzak/player/multiplayer.rb', line 10 def players @players end |
Class Method Details
.available? ⇒ Boolean
Returns whether or not all of the players are available.
13 14 15 16 |
# File 'lib/muzak/player/multiplayer.rb', line 13 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.
33 34 35 36 |
# File 'lib/muzak/player/multiplayer.rb', line 33 def activate! debug "activating #{self.class}" @players.each(&:activate!) end |
#clear_queue ⇒ void
This method returns an undefined value.
Clears the internal queue.
130 131 132 133 |
# File 'lib/muzak/player/multiplayer.rb', line 130 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.
40 41 42 43 |
# File 'lib/muzak/player/multiplayer.rb', line 40 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.
94 95 96 97 |
# File 'lib/muzak/player/multiplayer.rb', line 94 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.
103 104 105 106 |
# File 'lib/muzak/player/multiplayer.rb', line 103 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.
85 86 87 88 |
# File 'lib/muzak/player/multiplayer.rb', line 85 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.
111 112 113 |
# File 'lib/muzak/player/multiplayer.rb', line 111 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.
70 71 72 |
# File 'lib/muzak/player/multiplayer.rb', line 70 def next_song @players.each(&:next_song) end |
#now_playing ⇒ Song?
Get the currently loaded song.
137 138 139 140 |
# File 'lib/muzak/player/multiplayer.rb', line 137 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.
56 57 58 59 |
# File 'lib/muzak/player/multiplayer.rb', line 56 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.
48 49 50 51 |
# File 'lib/muzak/player/multiplayer.rb', line 48 def play return unless running? @players.each(&:play) end |
#playing? ⇒ Boolean
Returns Whether or not any of the players are currently playing.
62 63 64 65 |
# File 'lib/muzak/player/multiplayer.rb', line 62 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.
77 78 79 |
# File 'lib/muzak/player/multiplayer.rb', line 77 def previous_song @players.each(&:previous_song) end |
#running? ⇒ Boolean
Returns whether or not any of the players are currently running.
27 28 29 |
# File 'lib/muzak/player/multiplayer.rb', line 27 def running? @players.any?(&:running?) end |
#shuffle_queue ⇒ void
This method returns an undefined value.
Shuffle the internal queue.
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/muzak/player/multiplayer.rb', line 117 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 |