Class: Muzak::Player::VLC
- Inherits:
-
StubPlayer
- Object
- StubPlayer
- Muzak::Player::VLC
- Defined in:
- lib/muzak/player/vlc.rb
Overview
Exposes a VLC process to muzak for playback control.
Instance Attribute Summary
Attributes inherited from StubPlayer
Class Method Summary collapse
-
.available? ⇒ Boolean
Whether or not VLC is available.
Instance Method Summary collapse
-
#activate! ⇒ void
Activates a VLC process.
-
#clear_queue ⇒ void
Clear VLC's internal queue.
-
#deactivate! ⇒ void
Deactivates the VLC process, if one is running.
-
#enqueue_album(album) ⇒ void
Tell VLC to add the given album to its queue.
-
#enqueue_playlist(playlist) ⇒ void
Tell VLC to add the given playlist to its queue.
-
#enqueue_song(song) ⇒ void
Tell VLC to add the given song to its queue.
-
#list_queue ⇒ Array<Song>
Get VLC's internal queue.
-
#load_song(song) ⇒ void
private
Load a song into VLC.
-
#next_song ⇒ void
Tell VLC to play the next song in its queue.
-
#now_playing ⇒ Song?
Get VLC's currently loaded song.
-
#pause ⇒ void
Tell VLC to pause playback.
-
#play ⇒ void
Tell VLC to begin playback.
-
#playing? ⇒ Boolean
Whether or not VLC is currently playing.
-
#previous_song ⇒ void
Tell VLC to play the previous song in its queue.
-
#running? ⇒ Boolean
Whether or not the current instance is running.
-
#shuffle ⇒ void
Shuffle VLC's internal queue.
Methods inherited from StubPlayer
#initialize, player_name, #shuffle_queue
Methods included from Utils
album_art?, #build_response, #danger, #debug, #debug?, #error, #error!, music?, #output, #pretty, #verbose, #verbose?, which?
Constructor Details
This class inherits a constructor from Muzak::Player::StubPlayer
Class Method Details
Instance Method Details
#activate! ⇒ void
This method returns an undefined value.
Activates a VLC process.
21 22 23 24 25 26 27 28 29 |
# File 'lib/muzak/player/vlc.rb', line 21 def activate! return if running? debug "activating #{self.class}" @vlc = ::VLC::System.new instance.event :player_activated end |
#clear_queue ⇒ void
This method returns an undefined value.
Clear VLC's internal queue.
137 138 139 140 |
# File 'lib/muzak/player/vlc.rb', line 137 def clear_queue return unless running? @vlc.clear end |
#deactivate! ⇒ void
This method returns an undefined value.
Deactivates the VLC process, if one is running.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/muzak/player/vlc.rb', line 33 def deactivate! return unless running? debug "deactivating #{self.class}" @vlc.client.disconnect @vlc.server.stop instance.event :player_deactivated end |
#enqueue_album(album) ⇒ void
Activates VLC if not already activated.
This method returns an undefined value.
Tell VLC to add the given album to its queue.
97 98 99 100 101 102 103 |
# File 'lib/muzak/player/vlc.rb', line 97 def enqueue_album(album) activate! unless running? album.songs.each do |song| load_song song end end |
#enqueue_playlist(playlist) ⇒ void
Activates VLC if not already activated.
This method returns an undefined value.
Tell VLC to add the given playlist to its queue.
109 110 111 112 113 114 115 |
# File 'lib/muzak/player/vlc.rb', line 109 def enqueue_playlist(playlist) activate! unless running? playlist.songs.each do |song| load_song song end end |
#enqueue_song(song) ⇒ void
Activates VLC if not already activated.
This method returns an undefined value.
Tell VLC to add the given song to its queue.
87 88 89 90 91 |
# File 'lib/muzak/player/vlc.rb', line 87 def enqueue_song(song) activate! unless running? load_song song end |
#list_queue ⇒ Array<Song>
Implement this.
This includes songs already played.
Get VLC's internal queue.
121 122 123 124 125 126 |
# File 'lib/muzak/player/vlc.rb', line 121 def list_queue debug @vlc.playlist.to_s danger "this player doesn't support list_queue" # TODO: figure out how to get VLC::Client#playlist to return filenames [] end |
#load_song(song) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Load a song into VLC.
154 155 156 157 |
# File 'lib/muzak/player/vlc.rb', line 154 def load_song(song) @vlc.add_to_playlist song.path @vlc.play if Config.autoplay end |
#next_song ⇒ void
Does nothing if the current song is the last.
This method returns an undefined value.
Tell VLC to play the next song in its queue.
72 73 74 |
# File 'lib/muzak/player/vlc.rb', line 72 def next_song @vlc.next end |
#now_playing ⇒ Song?
Get VLC's currently loaded song.
144 145 146 147 148 |
# File 'lib/muzak/player/vlc.rb', line 144 def return unless Song.new(@vlc.status[:file]) end |
#pause ⇒ void
Does nothing is playback is already paused.
This method returns an undefined value.
Tell VLC to pause playback.
56 57 58 59 60 |
# File 'lib/muzak/player/vlc.rb', line 56 def pause return unless running? @vlc.pause end |
#play ⇒ void
Does nothing is playback is already in progress.
This method returns an undefined value.
Tell VLC to begin playback.
47 48 49 50 51 |
# File 'lib/muzak/player/vlc.rb', line 47 def play return unless running? @vlc.play end |
#playing? ⇒ Boolean
Returns whether or not VLC is currently playing.
63 64 65 66 67 |
# File 'lib/muzak/player/vlc.rb', line 63 def return false unless running? @vlc. end |
#previous_song ⇒ void
Restarts the song if the current song is the first.
This method returns an undefined value.
Tell VLC to play the previous song in its queue.
79 80 81 |
# File 'lib/muzak/player/vlc.rb', line 79 def previous_song @vlc.previous end |
#running? ⇒ Boolean
Returns whether or not the current instance is running.
15 16 17 |
# File 'lib/muzak/player/vlc.rb', line 15 def running? !!@vlc&.connected? end |
#shuffle ⇒ void
Implement this.
This method returns an undefined value.
Shuffle VLC's internal queue.
131 132 133 |
# File 'lib/muzak/player/vlc.rb', line 131 def shuffle danger "this player doesn't support shuffling (?)" end |