class Muzak::Player::VLC

Exposes a VLC process to muzak for playback control.

Public Class Methods

available?() click to toggle source

@return [Boolean] whether or not VLC is available

# File lib/muzak/player/vlc.rb, line 10
def self.available?
  Utils.which?("vlc") && Utils.which?("cvlc")
end

Public Instance Methods

activate!() click to toggle source

Activates a VLC process. @return [void]

# 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() click to toggle source

Clear VLC's internal queue. @return [void]

# File lib/muzak/player/vlc.rb, line 137
def clear_queue
  return unless running?
  @vlc.clear
end
deactivate!() click to toggle source

Deactivates the VLC process, if one is running. @return [void]

# 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) click to toggle source

Tell VLC to add the given album to its queue. @param album [Album] the album to add @return [void] @note Activates VLC if not already activated.

# 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) click to toggle source

Tell VLC to add the given playlist to its queue. @param playlist [Playlist] the playlist to add @return [void] @note Activates VLC if not already activated.

# 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) click to toggle source

Tell VLC to add the given song to its queue. @param song [Song] the song to add @return [void] @note Activates VLC if not already activated.

# File lib/muzak/player/vlc.rb, line 87
def enqueue_song(song)
  activate! unless running?

  load_song song
end
list_queue() click to toggle source

Get VLC's internal queue. @return [Array<Song>] all songs in VLC's queue @note This includes songs already played. @todo Implement this.

# 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) click to toggle source

Load a song into VLC. @param song [Song] the song to load @return [void] @api private

# 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() click to toggle source

Tell VLC to play the next song in its queue. @return [void] @note Does nothing if the current song is the last.

# File lib/muzak/player/vlc.rb, line 72
def next_song
  @vlc.next
end
now_playing() click to toggle source

Get VLC's currently loaded song. @return [Song, nil] the currently loaded song

# File lib/muzak/player/vlc.rb, line 144
def now_playing
  return unless playing?

  Song.new(@vlc.status[:file])
end
pause() click to toggle source

Tell VLC to pause playback. @return [void] @note Does nothing is playback is already paused.

# File lib/muzak/player/vlc.rb, line 56
def pause
  return unless running?

  @vlc.pause
end
play() click to toggle source

Tell VLC to begin playback. @return [void] @note Does nothing is playback is already in progress.

# File lib/muzak/player/vlc.rb, line 47
def play
  return unless running?

  @vlc.play
end
playing?() click to toggle source

@return [Boolean] whether or not VLC is currently playing.

# File lib/muzak/player/vlc.rb, line 63
def playing?
  return false unless running?

  @vlc.playing?
end
previous_song() click to toggle source

Tell VLC to play the previous song in its queue. @return [void] @note Restarts the song if the current song is the first.

# File lib/muzak/player/vlc.rb, line 79
def previous_song
  @vlc.previous
end
running?() click to toggle source

@return [Boolean] whether or not the current instance is running.

# File lib/muzak/player/vlc.rb, line 15
def running?
  !!@vlc&.connected?
end
shuffle() click to toggle source

Shuffle VLC's internal queue. @return [void] @todo Implement this.

# File lib/muzak/player/vlc.rb, line 131
def shuffle
  danger "this player doesn't support shuffling (?)"
end